hdu 2616 Kill the monster(暴搜)
来源:互联网 发布:刘义军 知乎 编辑:程序博客网 时间:2024/05/01 07:53
想了许久的DP,结果直接上手暴搜就行了。。。
#include<stdio.h>#include<string.h>#define N 11int a[N],b[N],mark[N];int ans,cnt;int n,m;int Min(int x,int y){ if(x<y) return x; return y;}void fun(int m,int cnt){ int i; for(i=1;i<=n;i++) { if(mark[i]==-1) continue; if(m>b[i]) { mark[i]=-1;m-=a[i];cnt++; if(m<=0) ans=Min(ans,cnt); fun(m,cnt);mark[i]=0;m+=a[i];cnt--; } else { mark[i]=-1;m-=2*a[i];cnt++; if(m<=0) ans=Min(ans,cnt); fun(m,cnt);mark[i]=0;m+=2*a[i];cnt--; } } return ;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { int i; memset(mark,0,sizeof(mark)); for(i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]); ans=12; cnt=0; for(i=1;i<=n;i++) { if(m>b[i]) { mark[i]=-1; m-=a[i]; cnt++; if(m<=0) { ans=1; break; } fun(m,cnt); mark[i]=0; m+=a[i];cnt--; } else { mark[i]=-1;m-=2*a[i];cnt++; if(m<=0) { ans=1; break; } fun(m,cnt); mark[i]=0;m+=2*a[i];cnt--; } } if(ans!=12) printf("%d\n",ans); else printf("-1\n"); } return 0;}
- 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
- 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)
- 【DFS】hdu 2616 Kill the monster
- HDU 2616 Kill the monster 简单DFS
- 杭电ACM HDU 2616 Kill the monster
- hdu 2616 Kill the monster(简单回溯搜索)
- Kill the monster(深搜)
- 引用计数的原理和实例
- 10个好用的集资网站博客系统主题模板
- POJ 1159 Palindrome(DP)
- Java 语言的 XPath API
- [leetcode] Remove Duplicates from Sorted Array II
- hdu 2616 Kill the monster(暴搜)
- 安卓环境搭建
- 二叉排序数的总结
- 解压zip
- 数字和的个数
- android自动更新软件版本
- apache负载均衡
- ffmpeg解码jpg并编码成h264
- UVA 1356/ ZOJ 2614 Bridge 弧长积分+二分