hdu 2616 Kill the monster(简单回溯搜索)
来源:互联网 发布:hammer.js教程 编辑:程序博客网 时间:2024/05/21 21:40
很简单的一道回溯搜索题目!!!、
#include<stdio.h>
#include<string.h>#define inf 99999999
int a[20],b[20],visit[20];
int n,m,min;
int dfs(int t,int hp)
{
int i;
if(t>n)
return -1;
if(hp<=0)
{
if(min>t)
min=t;
return min;
}
for(i=1;i<=n;i++)
if(visit[i]==0)
{
visit[i]=1;
if(hp<=b[i])
dfs(t+1,hp-2*a[i]);
else
dfs(t+1,hp-a[i]);
visit[i]=0;
}
return -1;
}
int main()
{
int ans,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
min=inf;
memset(visit,0,sizeof(visit));
for(i=1;i<=n;i++)
scanf("%d%d",&a[i],&b[i]);
ans=dfs(0,m);
if(min==inf)
printf("-1\n");
else
printf("%d\n",min);
}
return 0;
}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2616
- hdu 2616 Kill the monster(简单回溯搜索)
- 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(深搜)
- 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 (暴力搜索 || 终极暴力全排列)
- hdu 2616 Kill the monster(dfs+最优化剪枝+迭代加深搜索)
- HDU 2616 Kill the monster【全文翻译+详解】(广度优先搜索)
- 2013 Multi-University Training Contest 前8场总结
- TOJ 3445 POJ 2192 Zipper
- [leetcode] Path Sum
- mysql学习笔记--数据备份与还原
- uvc摄像头代码解析7
- hdu 2616 Kill the monster(简单回溯搜索)
- 2013年下半年计划
- Eclipse修改类不在重启Tomcat
- uva 1473 - Dome of Circus
- HDOJ 1196 Lowest Bit
- 【RSLogix5000】—(1.1)—厂房ControlLogix系统介绍(硬件介绍)——原理
- Ruby will_paginate分页排序及显示
- 黑马程序员 匿名内部类
- 黑马程序员——获取该字符串中的字母出现的次数