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. Python——graphviz及pydotplus安装步骤

    Python——graphviz及pydotplus安装步骤 一.安装Graphviz 网站:http://www.graphviz.org/download/ 下载msi文件 直接安装,完成之后添加 ...

  2. Kotlin介绍

    Kotlin介绍 转 https://www.jianshu.com/p/d30406daaf25 Google在今年的IO大会上宣布,将Android开发的官方语言更换为Kotlin,作为跟着Goo ...

  3. Vue事件 定义方法执行方法 获取数据 改变数据 执行方法传值 以及事件对象

    <template> <div id="app"> <!-- <img v-bind:src='url' /> <img :src= ...

  4. Vue-cli项目结构讲解

    |-- build // 项目构建(webpack)相关代码 | |-- build.js // 生产环境构建代码 | |-- check-version.js // 检查node.npm等版本 | ...

  5. TypeScript封装统一操作Mysql Mongodb Mssql的底层类库demo

    /* 功能:定义一个操作数据库的库 支持 Mysql Mssql MongoDb 要求1:Mysql MsSql MongoDb功能一样 都有 add update delete get方法 注意:约 ...

  6. Python的collections之defaultdict的使用及其优势

    user_dict = {} users = ["baoshan1", "baoshan2", "baoshan3","baosh ...

  7. Opencv加载网络图片

    opencv加载网络图片 #include <iostream> #include <opencv2/opencv.hpp> using namespace std; usin ...

  8. Spring cloud微服务安全实战-5-2前端页面改造

    创建一个新的maveb项目,做一个admin的管理界面 用angular写前面的页面. 先吧dependcency引用引进来. 前端的插件能帮我在springboot里面搭建出一个nodeJS的环境来 ...

  9. web端自动化——selenium3用法详解

    selenium中文学习文档链接:https://selenium-python-zh.readthedocs.io/en/latest/getting-started.html selenium3+ ...

  10. ffmpeg.编译(20191129)

    1.一步步实现windows版ijkplayer系列文章之一——Windows10平台编译ffmpeg 4.0.2,生成ffplay - HarlanC - 博客园.html(https://www. ...