HDU-2616
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1525 Accepted Submission(s): 1043Problem DescriptionThere 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.InputThe 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).OutputFor 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 Input3 10010 2045 895 403 10010 2045 905 403 10010 2045 845 40Sample Output32-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的更多相关文章
- HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)
主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...
- hdu 2616 Kill the monster (DFS)
Kill the monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 2616 暴力使用 dfs求最短路径(剪枝有点依稀)
Kill the monster Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- Maven - 下载JAR包
进入Spring官网http://projects.spring.io/spring-framework/假设我们想下载Spring发现仅仅能 通过Maven或Cradle进行下载了. 以下以Spri ...
- npm 淘宝设置代理
直接安装cnpm导致无限索引,因此直接使用代理 方法一: 直接在当前用户文件夹下,npmrc 文件上直接设置代理:registry=https://registry.npm.taobao.org 方法 ...
- jsp 下拉框首字母定位可检索
实现效果如图: 页面部分: (1)js中: (2)body中: JAVA代码部分: 控制器Controller中 写一个页面js中调用的方法: 引入jar包:
- React_Redux_Router
一.react_redux 比较好的blog: blog1, blog2, blog3 主要根据前两个blog总结如下: 1. React在组件内部(包括子组件)为单向数据流且自上向下通过props传 ...
- 五、Web框架基础(2)
Tornado 异步协程编程.(其实是异步IO而非真正的异步,从内核拷贝到用户空间的过程还是同步的) 适合用户量大.高并发,如抢票.网页游戏.在线聊天等场景:或大量HTTP持久连接,通过单TCP持久连 ...
- js thiskeyword
相信大家都接触过this了,那么 this究竟是什么意思呢?看其字面意思就是个代词.指代其它的一些东西. 那么我们在程序其中,事实上也是一样.this也是个代词. 比方我们在java其中,this的k ...
- Python使用Mysql过程中一些错误
Python使用Mysql过程中一些错误 ssh登录远程服务器 ssh ubuntu@xxx.xxx.xx.xx 第一:ubuntu终端中登录Mysql mysql -uroot -p 然后输入密码即 ...
- EasyDarwin开发的短视频拍摄、录制开源项目EasyVideoRecorder
在前面的博客<EasyDarwin开发出类似于美拍.秒拍的短视频拍摄SDK:EasyVideoRecorder>和<美拍.秒拍中安卓.IOS短视频拍摄的一些关键技术>中我们简单 ...
- extjs中新建窗体时,给窗体添加背景图片不显示问题之一
1.在extjs中新建窗体时,给窗体添加背景图片不显示,例如下面的代码. 不显示的原因:因为设置了 layout: 'fit', Ext.create('Ext.Window', { title: ...
- exp/imp三种模式——完全、用户、表
ORACLE数据库有两类备份方法.第一类为物理备份,该方法实现数据库的完整恢复,但数据库必须运行在归挡模式下(业务数据库在非归挡模式下运行),且需要极大的外部存储设备,例如磁带库:第二类备份方式为逻辑 ...