hdu2616Kill the monster 深搜
来源:互联网 发布:mac桌面卸载图标 编辑:程序博客网 时间:2024/05/29 14:31
题目大意是一个人要杀死一个怪物,怪物的血量HP。有n种方式,每种对怪物的伤害值不同。而且当怪物的HP小于等于某一值时,会造成double伤害。
搜索分两次,每次先对当前伤害做一次,然后dfs下一次伤害。感觉还是没有体会到dfs的核心。如何建立搜索的过程太模糊了
#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#include<vector>#include<cmath>#include<cctype>using namespace std;int n,m,temp,MIN;struct node { int spell; int HP; int vit;};node a[12];void dfs(int dep,int hp){ if(dep>MIN) return ; if(dep >= n) return ; if(dep <= n-1&&hp<=0) { MIN=dep; return ; } for(int i=0;i<n;i++) if(!a[i].vit) { int flag=hp; if(hp<=a[i].HP) hp-=a[i].spell*2; else hp-=a[i].spell; a[i].vit=1; dfs(dep+1,hp); hp=flag; a[i].vit=0; }}int main(){ int x,y; while(cin>>n>>m) { for(int i=0;i<n;i++) { cin>>x>>y; a[i].spell=x; a[i].HP=y; a[i].vit=0; } MIN=0xfff; int flag = m; for(int i=0;i<n;i++) { a[i].vit=1; if(a[i].HP>=m) m-=2*a[i].spell; else m-=a[i].spell; dfs(0,m); a[i].vit=0; m=flag; } if(MIN!=0xfff) cout<<MIN+1<<endl; else cout<<"-1"<<endl; }}
- hdu2616Kill the monster 深搜
- hdu2616Kill the monster(深搜)
- hdu2616Kill the monster(dfs)
- Kill the monster(深搜)
- The Monster
- The Monster
- hdu 2616 Kill the monster(深搜)
- HDU2616 Kill the monster(深搜DFS)
- hdu_2616 Kill the monster
- HDU2616 Kill the monster
- Save The Water Monster
- CF488C Fight the Monster
- - Kill the monster HDU2616
- hd2616 Kill the monster
- Kill the monster
- codeforces787A-The Monster
- A. The Monster
- HDU 2616 Kill the monster (深搜DFS)
- 怎么获取到View的位置View.getLocationInWindow()的为0
- struts.xml中关于param的配置
- 非阻塞Socket
- 如何把应用程序app编译进android系统
- Linux正则表达式技术指南
- hdu2616Kill the monster 深搜
- Android-ListView显示在最底部
- MSXML使用教程
- 大数据之路不乏荆棘,然则其中的机遇却高于一切
- 生成树的计数与基尔霍夫矩阵
- 在Windows里安装运行HAProxy【cygwin法】
- 在SSIS包中使用 Checkpoint从失败处重新启动包
- jeecms2012 框架分析 Spring mvc+hibernate+freemarker(开源项目)
- pl/sql 绑定变量