HDU 2616 Kill the monster
来源:互联网 发布:hbo 知乎 编辑:程序博客网 时间:2024/05/22 01:51
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.
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-1AuthoryifenfeiSource奋斗的年代
一道數據量很小的常規DFS搜索題。
#include<iostream>#include<cstring>#include<string>#include<algorithm>using namespace std;#define ll long long int#define INF 0x3f3f3f3fint n; int m; int cnt;struct node{ int A; int M;}a[15];int vis[15];void dfs(int c, int s) //s為怪物血量,c為當前步驟數{ if (s <= 0 && cnt > c) { cnt = c; return; } if (c > cnt)//剪枝操作 { return; } for (int i = 0; i < n; i++) { if (!vis[i]) { vis[i] = 1; int t = (s <= a[i].M ? s - 2 * a[i].A : s - a[i].A); dfs(c + 1, t); vis[i] = 0; } }}int main(){ while (cin >> n >> m) { memset(vis, 0, sizeof(vis)); for (int i = 0; i < n; i++) { cin >> a[i].A >> a[i].M; } cnt = INF; dfs(0, m); if (cnt == INF) { cout << "-1" << endl; } else { cout << cnt << endl; } } return 0;}
阅读全文
0 0
- hdu 2616 Kill the monster
- HDU 2616 Kill the monster
- HDU 2616 Kill the monster
- hdu(2616)Kill the monster
- HDU 2616 Kill the monster
- hdu 2616 Kill the monster
- HDU-2616-Kill the monster
- HDU 2616 Kill the monster
- hdu 2616 Kill the monster(深搜)
- hdu 2616 Kill the monster(DFS)
- hdu 2616 Kill the monster(暴搜)
- 【DFS】hdu 2616 Kill the monster
- HDU 2616 Kill the monster 简单DFS
- hdu 2616 Kill the monster(dfs)
- 杭电ACM HDU 2616 Kill the monster
- hdu 2616 Kill the monster(简单回溯搜索)
- HDU 2616 Kill the monster (深搜DFS)
- 杭电 2616 Kill the monster
- 下拉框支持输入且可以模糊匹配
- hud6082度度熊与邪恶大魔王(完全背包)
- HTML5新增标签以及扩展属性
- centos 7 部署 open-falcon 0.2.0[原文复制版]
- 查看表创建的sql脚本以及字段注释
- HDU 2616 Kill the monster
- mysql LImit 慢查询报警优化
- mac 有线 QQ能上,但网页不能上
- 当比特币重回新高的时候,业界更关心的是这个神秘的交易员
- 机器学习-朴素贝叶斯
- SQL 语句记录
- 洛谷P1551 亲戚
- Linux那些事(3)-Linux文本与图形界面详解
- Cannot find autoconf