(DFS) Kill the monster -- HDOJ
来源:互联网 发布:美国大学学生会 知乎 编辑:程序博客网 时间:2024/06/05 20:44
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 177 Accepted Submission(s): 128
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.
Input
The input contains multiple test cases.
Each test case include, first two integers n, m (2
#include<iostream>#include<string.h>#include<string>#include<stdio.h>#include<algorithm>#include<queue>#include<math.h>#define PI acos(-1.0)#define eps 0.00000001using namespace std;typedef struct Node{ int a,m;}Node;int n,M,ans;Node spe[12];void DFS(int sum,int vis[],int num){ // cout << sum <<endl; if(sum <= 0) { ans = min(ans,num); return; } for(int i=0; i<n; ++i) { if(!vis[i]) { vis[i] = 1; if(spe[i].m >= sum) DFS(sum - 2*spe[i].a,vis,num+1); else DFS(sum - spe[i].a,vis,num+1); vis[i] = 0; } }}main(void){// freopen("in.txt","r",stdin); while(scanf("%d %d",&n,&M) != EOF) { int vis[n]; memset(vis,0,sizeof(vis)); for(int i=0; i<n; ++i) { scanf("%d %d",&spe[i].a,&spe[i].m); } ans = 999999; DFS(M,vis,0); if(ans == 999999) ans = -1; cout << ans <<endl; } return 0;}
- (DFS) Kill the monster -- HDOJ
- HDOJ 2616 Kill the monster(DFS+BFS)
- HDOJ 2616 Kill the monster (DFS)
- hdu 2616 Kill the monster(DFS)
- A - Kill the monster (DFS)
- hdu 2616 Kill the monster(dfs)
- HDU 2616 Kill the monster (深搜DFS)
- 【DFS】hdu 2616 Kill the monster
- HDU 2616 Kill the monster 简单DFS
- HDU2616 Kill the monster(深搜DFS)
- Kill the monster(深搜)
- ACM-DFS之Kill The Monster——hdu2616
- hdu 2616 Kill the monster(深搜)
- hdu 2616 Kill the monster(暴搜)
- ACdream Kill The Monster(线性dp)
- ACdream 1072 Kill The Monster (dp)
- hdu_2616 Kill the monster
- HDU2616 Kill the monster
- 结构体重载运算符版高精度!
- nginx之缓存
- TimeUtils,有关时间处理的工具类
- pvanet 修改demo.py来载入自己训练过的模型并显示检测结果
- Java集合之LinkedList(实现List接口)
- (DFS) Kill the monster -- HDOJ
- Arcgis javascript那些事儿(十五)——影像服务的发布与使用
- java 后台发送http请求
- 数据结构算法之字符串
- HDOJ1455 (DFS+剪枝优化)和 HDOJ1518可做类比
- 以MongoDB为例与关系型数据库比较
- const
- 改造PullToRefresh下拉刷新和上拉加载
- android sharepreference全解