hdu 2616 Kill the monster (DFS)
Kill the monster
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 778 Accepted Submission(s): 556
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.
Each test case include, first two integers n, m (2<n<10, 1<m<10^7), express how many spells yifenfei has.
Next n line , each line express one spell. (Ai, Mi).(0<Ai,Mi<=m).
10 20
45 89
5 40
3 100
10 20
45 90
5 40
3 100
10 20
45 84
5 40
2
-1
//109MS 228K 694 B G++ 姜伯约
/* 题意:
有n组数据,和怪兽血量m,每组数据有两个数,第一个为普通伤害值,
第二个为怪兽血量少于该值时将造成双倍伤害,,求最少攻击次数,
杀不死则输出-1. DFS:
比较明显的dfs,时间复杂度为O(n!),数据比较小而且不强,可以直接DFS
过了 */
#include<stdio.h>
#include<string.h>
int n,m;
int a[][];
int vis[];
int cnt;
void dfs(int c,int s)
{
if(s<= && c<cnt){
cnt=c;
return;
}
if(c>=cnt) return;
for(int i=;i<n;i++)
if(!vis[i]){
vis[i]=;
int temp=(s<=a[i][]?s-*a[i][]:s-a[i][]);
dfs(c+,temp);
vis[i]=;
} }
int main(void)
{
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d%d",&a[i][],&a[i][]);
memset(vis,,sizeof(vis));
cnt=;
dfs(,m);
if(cnt==) puts("-1");
else printf("%d\n",cnt);
}
}
hdu 2616 Kill the monster (DFS)的更多相关文章
- HDU 2616 Kill the monster (暴力搜索 || 终极全阵列暴力)
主题链接:HDU 2616 Kill the monster 意甲冠军:有N技能比赛HP有M怪物,技能(A,M),能伤害为A.当怪兽HP<=M时伤害为2*A. 求打死怪兽(HP<=0)用的 ...
- hdu 2660 Accepted Necklace(dfs)
Problem Description I have N precious stones, and plan to use K of them to make a necklace for my mo ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU 1728 逃离迷宫(DFS)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1728 题目: 逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) ...
- HDU 6351 Beautiful Now(DFS)多校题解
思路:一开始对k没有理解好,题意说交换k次,如果我们不需要交换那么多,那么可以重复自己交换自己,那么k其实可以理解为最多交换k次.这道题dfs暴力就行,我们按照全排列最大最小去找每一位应该和后面哪一位 ...
- HDU 2553(N皇后)(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=2553 i表示行,map[i]表示列,然后用DFS遍历回溯 可以参考这篇文章: http://blog.csdn. ...
- 2017ACM暑期多校联合训练 - Team 1 1003 HDU 6035 Colorful Tree (dfs)
题目链接 Problem Description There is a tree with n nodes, each of which has a type of color represented ...
- HDU 5012 骰子旋转(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=5012 保存骰子的状态,然后用dfs或者bfs搜索 还是再讲一下dfs 我们的目标是找一个与b相同,且转次数最少的 ...
- HDU 5305 Friends(简单DFS)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
随机推荐
- 改变shape solid color
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http: ...
- es6-promise.auto.js
使用sweetalert2的IE浏览器报错,导入文件 链接:https://pan.baidu.com/s/1mOcsN_o8m-7I7Rej1NPkiw 提取码:9xsj
- DB总结1
DBA 重构 data new york committee cobol codasyl journal DDL DML 关系演算 域关系演算语言(QBE) 元祖关系演算语言 ...
- Session和cookic
session是无状态的方式,服务器存储机制,当用户第一次请求服务器,服务器会给客户分配一个标识id,客户端再次访问服务器,根据session id 去访问服务器数据库,返回信息,同时session ...
- react搭建一个框架(react-redux-axios-antd Designs)
废话不多说,先给一个github案例:前往.. 1.create-react-app <文件名> 安装router:npm i react-router-dom -S; npm inst ...
- cncert阅读报告
信息安全阅读报告 Problem 1: 国家计算机网络应急技术处理协调中心(简称“国家互联网应急中心”,英文缩写为“CNCERT”或“CNCERT/CC”)作为我国非政府层面网络安全应急体系核心技术协 ...
- 转:mysql远程连接 Host * is not allowed to connect to this MySQL server
在本机登入mysql后,更改"mysql"数据库里的"user"表里的"host"项,从"localhost"改为'%' ...
- linux面试集
shell:1.$# 和 $*之类的特殊变量 特殊变量列表 变量 含义 $0 当前脚本的文件名 $n 传递给脚本或函数的参数.n是一个数字,表示第几个参数.例如,第一个参数就是$1 $# 传递给脚本或 ...
- PHP生成特定长度的纯字母字符串
PHP中,md5().uniqid()函数可以返回32位和13位不重复的字符串,但是这些字符串都可能包含有数字.如果需要纯字母的字符串,而且长度不定,比如8位,那么直接用这两个函数无法达到效果. 这时 ...
- Spark调优之JVM调优
一.JVM调优 JVM: 老年代: 存放少量生命周期长的对象,如连接池 年轻代: Spark task执行算子函数自己创建的大量对象 JVM机制: 对象进入java虚拟机之后会放在eden区域和一个s ...