Kill the monster

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1525    Accepted Submission(s): 1043

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

题意:

有n个符咒,怪兽有m点血。每个符咒有两个属性:

1.伤害A;

2.在怪物血量低于M时造成2*A点伤害。

AC代码:

 #include<bits/stdc++.h>
using namespace std; struct node{
int x,y;
}a[]; bool vis[];
int n,m,ans; void dfs(int m,int len){
if(len>=ans)
return;
if(m<=){
ans=min(ans,len);
return;
}
for(int i=;i<n;i++){
if(vis[i]==){
vis[i]=;
if(m<=a[i].y)
dfs(m-*a[i].x,len+);
else
dfs(m-a[i].x,len+);
vis[i]=;
}
}
} int main(){
while(cin>>n>>m){
for(int i=;i<n;i++){
cin>>a[i].x>>a[i].y;
}
memset(vis,,sizeof(vis));
ans=;
dfs(m,);
if(ans>){
cout<<-<<endl;
}
else{
cout<<ans<<endl;
}
}
return ;
}

HDU-2616的更多相关文章

  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 2616 Kill the monster (DFS)

    Kill the monster Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 2616 暴力使用 dfs求最短路径(剪枝有点依稀)

    Kill the monster Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  10. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. 【转载】读懂IL代码就这么简单(三)完结篇

    一 前言 写了两篇关于IL指令相关的文章,分别把值类型与引用类型在 堆与栈上的操作区别详细的写了一遍这第三篇也是最后一篇,之所以到第三篇就结束了,是因为以我现在的层次,能理解到的都写完了,而且个人认为 ...

  2. nodejs如何使用mongo数据库

    nodejs如何使用mongo数据库 首先,请参考下面两个链接,配置并运行express和mongodb. 1.使用express生成一个空白网站http://cnodejs.org/topic/50 ...

  3. UVA1422-Processor(二分法+优先队列)

    option=com_onlinejudge&Itemid=8&category=512&page=show_problem&problem=4168"> ...

  4. Finder 快捷键

    记录几个常用的 Finder 快捷键: 复制 Finder 里选中的路径:option+cmd+c 地址栏跳到指定路径:shift+cmd+g 增加标签:cmd+t 显示/隐藏 标签栏:shift+c ...

  5. 去除input框的值

    onfocus="this.value=' ';" <input type="text" name="buynum" id=" ...

  6. java 的PO、VO、TO、BO、DAO、POJO解释(转载)

    PO(persistent object):持久化对象 在O/R映射时出现的概念.如果没有O/R映射,则不存在PO.通常对应数据模型(数据库),本身还有部分业务逻辑的处理.可以看作是与数据库中的表相映 ...

  7. RecyclerView的那点事儿

    RecyclerView 控件简单介绍 ListView的升级版 LinearLayoutManager GridLayoutManager StaggeredGridLayoutManager 定制 ...

  8. extend选项和delimiters选项 vue 数据绑定 html form 对比 id重复

    {{define "chkUrl"}}<!DOCTYPE html><html lang="zh-cmn-Hans"><head& ...

  9. mount available

    Mount (computing), the process of making a file system accessible mount (Unix), the utility in Unix- ...

  10. windows IDA 调试SO

    还是参考了网上的很多资料,感谢这些前辈的分享. ===================================================================== 环境:win ...