hdu 2616 Kill the monster(深搜)
来源:互联网 发布:淘宝旺旺名字大全 编辑:程序博客网 时间:2024/05/16 04:47
http://acm.hdu.edu.cn/showproblem.php?pid=2616
题意:
有n种技能,每种技能只能用一次,怪物有m点血,问最少需要多少种技能可以把怪物杀死。
每种技能有两个数值a和b,a表示攻击力,b表示当怪物的血量小于等于b时,这种技能的攻击力可以变为2a。
一点攻击力可以杀掉怪物一点血。
简单深搜
加了一个剪枝后从 421 MS 瞬间 降到 93MS
code:
#include <stdio.h>#include <string.h>struct node { int M, spell;} a[11];int hp, n;int vis[11];int ans ;void dfs(int k, int HP) { int i; if(k>=ans) return ; if(HP<=0) { if(ans>k) ans = k; return; } for(i=1; i<=n; i++) if(!vis[i]) { vis[i] = 1; HP<=a[i].M? dfs(k+1,HP-a[i].spell*2): dfs(k+1,HP-a[i].spell); vis[i] = 0; }}int main() { int i; while(~scanf("%d%d",&n,&hp)) { for(i=1; i<=n; i++) scanf("%d%d",&a[i].spell,&a[i].M); ans = 12; memset(vis,0,sizeof(vis)); dfs(0,hp); if(ans !=12) printf("%d\n",ans); else printf("-1\n"); } return 0;}
- hdu 2616 Kill the monster(深搜)
- hdu 2616 Kill the monster(DFS)
- 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
- 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
- Kill the monster(深搜)
- 【DFS】hdu 2616 Kill the monster
- HDU 2616 Kill the monster 简单DFS
- 杭电ACM HDU 2616 Kill the monster
- hdu 2616 Kill the monster(简单回溯搜索)
- Ubuntu下调试Qt报错ptrace operation not permitted
- socket中的SO_REUSEADDR
- VMware8安装centos的vmtool 增强包的问题,终端界面下
- Socket programming FAQ
- 黑马程序员 自学日记(二) java基础 二
- hdu 2616 Kill the monster(深搜)
- struts2上传多个文件,下载 配制!代码
- 黑马程序员 自学日记(三)面向对象 一
- Android展开/收缩列表 ExpandableListView 每次只能有一个项目是展开的
- MonoDevelop 4.0.9 on CentOS 6.3 安装笔记
- Android静态变量的生命周期
- linux 编译配置 cocos2d-x 开发环境 [笔记一]
- viewgroup 循环
- js五子棋