Kill the monster

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

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
 #include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int mapp[11][2];
int vis[11];
int minn,n,m,flag;
void dfs(int bloor,int time)
{
 int i,j;
 if(bloor<=0)
 {
 // cout<<".."<<endl;
  if(minn>time) minn=time;
 // cout<<maxx<<endl;
  flag=1;
  return;
 }
 if(time>=minn) return ;//  当次数比以前走过的次数多的时候 剪去
 for(i=1;i<=n;i++)
 {
  if(vis[i]==1) continue;
  vis[i]=1;
 // cout<<".."<<endl;
  if(bloor<=mapp[i][1])
  {
  // cout<<".."<<endl;
      dfs(bloor-2*mapp[i][0],time+1); 
     }
  else
  {
  // cout<<".."<<endl;
   dfs(bloor-mapp[i][0],time+1);
  }
  vis[i]=0;
 }
}
int main()
{
 int i,j;
 while(cin>>n>>m)
 {
  for(i=1;i<=n;i++)
  {
   scanf("%d %d",&mapp[i][0],&mapp[i][1]);
  // cout<<mapp[i][0]<<mapp[i][1]<<endl;
  }
  memset(vis,0,sizeof(vis));
  flag=0;
  minn=999;
  dfs(m,0);
  if(flag==0) printf("-1\n");
  else printf("%d\n",minn);
 }
 return 0;
}

hdu 2616 暴力使用 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 1501 Zipper 【DFS+剪枝】

    HDU 1501 Zipper [DFS+剪枝] Problem Description Given three strings, you are to determine whether the t ...

  3. HDU 4607 Park Visit 两次DFS求树直径

    两次DFS求树直径方法见 这里. 这里的直径是指最长链包含的节点个数,而上一题是指最长链的路径权值之和,注意区分. K <= R: ans = K − 1; K > R:   ans = ...

  4. HDU 3416 Marriage Match IV (最短路径,网络流,最大流)

    HDU 3416 Marriage Match IV (最短路径,网络流,最大流) Description Do not sincere non-interference. Like that sho ...

  5. HDOJ(HDU).1045 Fire Net (DFS)

    HDOJ(HDU).1045 Fire Net [从零开始DFS(7)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HD ...

  6. HDOJ(HDU).1241 Oil Deposits(DFS)

    HDOJ(HDU).1241 Oil Deposits(DFS) [从零开始DFS(5)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

  7. HDOJ(HDU).1035 Robot Motion (DFS)

    HDOJ(HDU).1035 Robot Motion [从零开始DFS(4)] 点我挑战题目 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DF ...

  8. DFS入门之二---DFS求连通块

    用DFS求连通块也是比较典型的问题, 求多维数组连通块的过程也称为--“种子填充”. 我们给每次遍历过的连通块加上编号, 这样就可以避免一个格子访问多次.比较典型的问题是”八连块问题“.即任意两格子所 ...

  9. 《算法导论》读书笔记之图论算法—Dijkstra 算法求最短路径

    自从打ACM以来也算是用Dijkstra算法来求最短路径了好久,现在就写一篇博客来介绍一下这个算法吧 :) Dijkstra(迪杰斯特拉)算法是典型的最短路径路由算法,用于计算一个节点到其他所有节点的 ...

随机推荐

  1. 都2019年了,Java为什么还在坚持多线程不选择协程?

    都2019年了,Java为什么还在坚持多线程不选择协程? - 知乎 https://www.zhihu.com/question/332042250/answer/734051666

  2. GIS自定义地理处理工具--极值提取

    GIS自定义地理处理工具--极值提取 关键词:最大值提取,最小值提取,极值提取,极小值提取,极大值提取 商务合作,科技咨询,版权转让:向日葵,135—4855__4328,xiexiaokui#qq. ...

  3. php递归注意事项

    /* 循环去除字符串左边的0 */ function removeLeftZero($str){ if($str['0'] == '0'){ $str = substr($str, '1'); rem ...

  4. Dart介绍和环境搭建

    /* Dart介绍: Dart是由谷歌开发的计算机编程语言,它可以被用于web.服务器.移动应用 和物联网等领域的开发. Dart诞生于2011年,号称要取代JavaScript.但是过去的几年中一直 ...

  5. 有关 MyEclipse->export runnable jar file选项 launch configuration里面没有可以选择的东西的解决方法

    为什么eclipse里export-->runnable jar file-->的launch configuration里面没有可以选择的东西或者新写的main方法却找不到呢? 将你程序 ...

  6. invalid application of ‘sizeof’ to incomplete type

    sizeof 后面所跟的数据类型没有定义,或者找不到定义的地方 eg: 头文件中定义结构体如下: struct PersonaL{ char name[]; int  age; }; 但是在cpp中使 ...

  7. mysql登录指令

    mysql -h 192.168.1.124 -u root -p -h后加mysql的ip,-u加用户名,-p会弹出输入密码

  8. ubuntu18.04手动安装二进制MySQL8.0

    wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz tar xvJf ...

  9. js实现深度优先遍历和广度优先遍历

    深度优先遍历和广度优先遍历 什么是深度优先和广度优先 其实简单来说 深度优先就是自上而下的遍历搜索 广度优先则是逐层遍历, 如下图所示 1.深度优先 2.广度优先 两者的区别 对于算法来说 无非就是时 ...

  10. STM32驱动模数转换芯片ADS1120(基础知识篇)第1篇

    1. 先看下ADS1120的结构图,ADS1120是个比较奇葩的ADC模数转换器,因为比较适用于热电阻之类的温度采集器.看下图,有个MUX多路复用器,应该是选择两个差分信号去测试,通过输入多路复用器 ...