hdu 2616 Kill the monster (DFS)
2024-10-21 23:17:44
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 778 Accepted Submission(s): 556
Problem Description
There is a mountain near yifenfei’s hometown. On the mountain lived a big monster. As a hero in hometown, yifenfei wants to kill it.
Now we know yifenfei have n spells, and the monster have m HP, when HP <= 0 meaning monster be killed. Yifenfei’s spells have different effect if used in different time. now tell you each spells’s effects , expressed (A ,M). A show the spell can cost A HP to monster in the common time. M show that when the monster’s HP <= M, using this spell can get double effect.
Now we know yifenfei have n spells, and the monster have m HP, when HP <= 0 meaning monster be killed. Yifenfei’s spells have different effect if used in different time. now tell you each spells’s effects , expressed (A ,M). A show the spell can cost A HP to monster in the common time. M show that when the monster’s HP <= M, using this spell can get double effect.
Input
The input contains multiple test cases.
Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
Output
For each test case output one integer that how many spells yifenfei should use at least. If yifenfei can not kill the monster output -1.
Sample Input
3 100
10 20
45 89
5 40
10 20
45 89
5 40
3 100
10 20
45 90
5 40
3 100
10 20
45 84
5 40
Sample Output
3
2
-1
2
-1
Author
yifenfei
Source
Recommend
//109MS 228K 694 B G++ 姜伯约
/* 题意:
有n组数据,和怪兽血量m,每组数据有两个数,第一个为普通伤害值,
第二个为怪兽血量少于该值时将造成双倍伤害,,求最少攻击次数,
杀不死则输出-1. DFS:
比较明显的dfs,时间复杂度为O(n!),数据比较小而且不强,可以直接DFS
过了 */
#include<stdio.h>
#include<string.h>
int n,m;
int a[][];
int vis[];
int cnt;
void dfs(int c,int s)
{
if(s<= && c<cnt){
cnt=c;
return;
}
if(c>=cnt) return;
for(int i=;i<n;i++)
if(!vis[i]){
vis[i]=;
int temp=(s<=a[i][]?s-*a[i][]:s-a[i][]);
dfs(c+,temp);
vis[i]=;
} }
int main(void)
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d%d",&a[i][],&a[i][]);
memset(vis,,sizeof(vis));
cnt=;
dfs(,m);
if(cnt==) puts("-1");
else printf("%d\n",cnt);
}
}
最新文章
- 常见类型,isset(),empty()判断
- FreeBSD应该装gnome3做桌面
- JavaScript进阶(二)
- 【Todo】LR-逻辑回归
- 5.3.1 新建Java工程和类
- magento 多域名多店铺
- 使用logback.xml配置来实现日志文件输出
- Android开发系列----sdk下载 环境准备
- Flas-SQLAchemy数据库操作使用学习笔记
- 23个mysql查询语句
- 删除bin后,Eclipse重新编译项目
- sql查询表说明
- datalist标签小结
- 浴室沉思:聊聊DAL和Repository
- 挂载U盘和移动硬盘
- android打包引用第三方jar出现的错误
- LDAP&;IMPLEMENTATION
- 12-Python操作json
- Vue diff 算法
- MySQL5.7.20安装过程报错CMake Error at cmake/boost.cmake:81 (MESSAGE):