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

最新文章

  1. 常见类型,isset(),empty()判断
  2. FreeBSD应该装gnome3做桌面
  3. JavaScript进阶(二)
  4. 【Todo】LR-逻辑回归
  5. 5.3.1 新建Java工程和类
  6. magento 多域名多店铺
  7. 使用logback.xml配置来实现日志文件输出
  8. Android开发系列----sdk下载 环境准备
  9. Flas-SQLAchemy数据库操作使用学习笔记
  10. 23个mysql查询语句
  11. 删除bin后,Eclipse重新编译项目
  12. sql查询表说明
  13. datalist标签小结
  14. 浴室沉思:聊聊DAL和Repository
  15. 挂载U盘和移动硬盘
  16. android打包引用第三方jar出现的错误
  17. LDAP&amp;IMPLEMENTATION
  18. 12-Python操作json
  19. Vue diff 算法
  20. MySQL5.7.20安装过程报错CMake Error at cmake/boost.cmake:81 (MESSAGE):

热门文章

  1. 在Linux上部署Kettle环境
  2. PHP:(一)安装并使用PHP
  3. 漂亮提醒框js
  4. 基于WSAAsyncSelect模型的两台计算机之间的通信
  5. IE6兼容png图片
  6. 内置函数系列之 filter
  7. php 利用composer引用第三方类库构建项目
  8. POJ 2676 数独(DFS)
  9. TI C6000 数据存储处理与性能优化
  10. Redis和Mecahe的简介