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 ;
}

最新文章

  1. 安装oracle
  2. MSSQ调优所需用的语句
  3. CentOS搭建NodeJS环境
  4. d3 scale 学习笔记
  5. [JS] JS模块化开发之RequireJS
  6. 别老扯什么Hadoop了,你的数据根本不够大
  7. css3设置边框属性
  8. [AngularJS] Best Practise - Resolve promises in router, defer controllers
  9. PDF数据防扩散系统方案
  10. Python日期操作
  11. [NOIP 2011]聪明的质监员
  12. Analyzing &#39;enq: HW - contention&#39; Wait Event (Doc ID 740075.1)
  13. HTML5_canvas_图片加载_双缓冲_跳帧闪烁问题
  14. Elastic Stack之Logstash进阶
  15. Error configuring application listener of class org.springframework.web.util
  16. go 通过http发送图片file内容
  17. SQL注入之Sqli-labs系列第五关和第六关(基于GET型的报错注入)
  18. centos7+hadoop完全分布式集群搭建
  19. Python: attrgetter()函数: 排序不支持原生比较的对象
  20. Grep console 设置

热门文章

  1. JavaScript 工厂模式和订阅模式
  2. DM8168 unrecoverable error: OMX_ErrorBadParameter (0x80001005) [resolved]
  3. STL之set具体解释(二)
  4. Intel&#174; RAID Software User’s Guide
  5. UITableView 自带编辑删除 自己定义button
  6. 关于移动端文字无法垂直居中(或line-height不起作用)的问题的解决方案(网摘)
  7. 简化Android的startActivityForResult调用
  8. python2&amp;python3的区别
  9. Java类加载器( 死磕8)
  10. Hadoop实战-Flume之Hdfs Sink(十)