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 ...
随机推荐
- Tomcat启动排查
Tomcat启动排查 一.参考 https://blog.csdn.net/baidu_32739019/article/details/64155136
- LeetCode700. Search in a Binary Search Tree
题目 给定二叉搜索树(BST)的根节点和一个值. 你需要在BST中找到节点值等于给定值的节点. 返回以该节点为根的子树. 如果节点不存在,则返回 NULL. 例如, 给定二叉搜索树: 4 / \ 2 ...
- C++ 编写的解码器小程序 map
c++ prime 5 ex11_4 代码如下 // ex11_4_word_transform.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h&quo ...
- 第34-1题:LeetCode112. Path Sum I
题目 给定一个二叉树和一个目标和,判断该树中是否存在根节点到叶子节点的路径,这条路径上所有节点值相加等于目标和. 说明: 叶子节点是指没有子节点的节点. 示例: 给定如下二叉树,以及目标和 sum ...
- SpringMVC使用ModelAndView的相对路径和绝对路径的问题
例如:abc/a/a.jsp,想要跳转到根目录的b.jsp 使用 ModelAndView 跳转, 若引用:org.springframework.web.portlet.ModelAndView 这 ...
- linux下安装xtrabackup
下载需要的版本的xtrabackup软件包,链接如下: https://www.percona.com/downloads/XtraBackup/LATEST/ percona-xtrabackup- ...
- linux常见内核参数
参数 描述 net.ipv4.ip_forward 接口间转发报文net.ipv4.tcp_tw_reuse 表示是否允许将处于 TIME-WAIT 状态的 socket (TIME-WAIT 的端口 ...
- 海龟绘图turtle模块的使用
在本章中,我们将编写简短的.简单的程序来创建漂亮的.复杂的视觉效果.为了做到这一点,我们可以使用海龟作图软件.在海龟作图中,我们可以编写指令让一个虚拟的(想象中的)海龟在屏幕上来回移动.这个海龟带着一 ...
- PHP提取奇数或偶数下标元素
该功能主要用到 array_filter() 函数,这个函数可以用回调函数过滤数组中的单元.用法: array array_filter ( array $array [, callable $cal ...
- Alter the structure of web pages with JavaScript
Most of the DOM methods you've seen so far are useful for identifying elements. Both getElementById ...