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.
 
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).
 
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

3 100
10 20
45 90
5 40

3 100
10 20
45 84
5 40

 
Sample Output
3
2
-1
 
Author
yifenfei
 
Source
 
Recommend
yifenfei   |   We have carefully selected several similar problems for you:  2614 1426 1258 2660 2514 
 
 //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);
}
}

hdu 2616 Kill the monster (DFS)的更多相关文章

  1. HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)

    主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...

  2. hdu 2660 Accepted Necklace(dfs)

    Problem Description I have N precious stones, and plan to use K of them to make a necklace for my mo ...

  3. hdu 1241:Oil Deposits(DFS)

    Oil Deposits Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  4. HDU 1728 逃离迷宫(DFS)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题目: 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others)  ...

  5. HDU 6351 Beautiful Now(DFS)多校题解

    思路:一开始对k没有理解好,题意说交换k次,如果我们不需要交换那么多,那么可以重复自己交换自己,那么k其实可以理解为最多交换k次.这道题dfs暴力就行,我们按照全排列最大最小去找每一位应该和后面哪一位 ...

  6. HDU 2553(N皇后)(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=2553 i表示行,map[i]表示列,然后用DFS遍历回溯 可以参考这篇文章: http://blog.csdn. ...

  7. 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)

    题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...

  8. HDU 5012 骰子旋转(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...

  9. HDU 5305 Friends(简单DFS)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

随机推荐

  1. 表单验证实现React-router跳转

    方法一:broserHistory.push handleSubmit(e){ e.preventDefault(); const path = '/demo'; broserHistory.push ...

  2. TCPIP协议编程:基于UDP协议的局域网聊天工具的研发

    任务目标 聊天器采用客户端/服务器(C/S)模式: 客户端利用UDP与服务器相连,客户端与客户端之间通过UDP相互通信: 服务器端具有服务器端口设置维护客户端个人信息,记录客户端状态,分配账号等: 客 ...

  3. laravel cache get 是如何调用的?

    本文使用版本为laravel5.5 cache get public function cache() { $c=\Cache::get('app'); if(!$c) { \Cache::put(' ...

  4. 图解HTTP总结(2)——简单的HTTP协议

    HTTP协议是一种不保存状态,即无状态(stateless)协议.HTTP协议自身不对请求和响应之间的通信状态进行保存.也就是说在HTTP这个级别,协议对于发送过的请求或响应都不做持久化处理. 使用H ...

  5. Python中的str

    str_lst = [ ('元素替换',), ('字符串切片',), ('字符串分割',), ('字符串连接',), ('元素计数',), ('寻找元素',), ('判断字符串的开头与结尾',), ( ...

  6. [CQOI2007]余数求和 (分块+数学

    题目描述 给出正整数n和k,计算G(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值,其中k mod i表示k除以i的余数.例如G(10, 5)=5 ...

  7. Leetcode 701. 二叉搜索树中的插入操作

    题目链接 https://leetcode.com/problems/insert-into-a-binary-search-tree/description/ 题目描述 给定二叉搜索树(BST)的根 ...

  8. contextmanager 的基本使用

    from contextlib import contextmanager 简化 With 语句: class MyResource:    def query(self):        print ...

  9. Java 的单元测试

    有点需要注意,当 JUnit 主线程退出,子线程也会跟着退出,需要使用子线程的 join() 方法使主线程等待 Maven 依赖 <dependency> <groupId>j ...

  10. Android 支付宝H5 没有回调

    今天测试反馈问题,说,手机上没有安装支付宝的,调用支付宝支付之后,没有回调.不提示成功也不提示失败. 我自己试了半天也都是没有问题 .后来终于可以试出来了. 发现原来是,清单里面注册的Activity ...