hd2616

hd2616

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<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).
Output
For each test case output one integer that how many spells yifenfei should use at least. If yifenfei can not kill the monster output -1.
Sample Input
3 100
10 20
45 89
5 40

3 100
10 20
45 90
5 40
3 100
10 20
45 84
5 40
Sample Output
3
2
-1

大概就是n表示的三次魔法,m表示的是hp值然后,下面三个是每个法术的普通伤害和低于他规定的值后翻倍;
用深度优先搜索暴力解题,其实dfs本质还是跟递归有关,还是不能学的僵化了。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int used[100];//标志变量
int a[100],b[100];//存储两个数
int ans;//判断变量
int cut=0;
int n, m;
void dfs(int bllod,int cut)
{
	if(cut>n)
		return ;
	if(bllod<=0&&cut<ans)
	{
		ans=cut; 
		return ;
	} 
	for(int i=0;i<n;i++){
		if(!used[i])
		{
			used[i]=1;
			if(bllod<=b[i])
				dfs(bllod-2*a[i],cut+1);
			else
				dfs(bllod-a[i],cut+1);
			used[i]=0;  
		}
	}
}
int main(){
	
	while(cin>>n>>m)
	{
		
		for(int i=0;i<n;i++)
		{
			cin >> a[i] >>b[i];
		} 
		memset(used,0,sizeof(used));
		ans=1314;
		dfs(m,cut);  
		if(ans!=1314)
			cout<<ans<<endl;
			else cout<<-1<<endl; 
			cut=0;
	 } 
	return 0;
} 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/114896.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • testlink安装教程_轻松吊安装

    testlink安装教程_轻松吊安装采用Xmapp的配置环境,TestLink轻松搞定!

    2022年9月18日
    3
  • Linux入门(三)

    Linux入门(三)

    2022年3月8日
    39
  • 前端第二章:8.HTML超链接代码写法;id属性

    前端第二章:8.HTML超链接代码写法;id属性一、超链接介绍0.超链接是行内元素,但是可以放块元素1.从一个页面跳转到另一个页面2.或者跳转到当前页面的其他位置3.href属性的值可以是外部网站,也可以是同一个目录下的地址文件,如xxx.html二、超链接·代码1.超链接写法:<ahref=”你想要跳转到的网址”>超链接的字样</a>2.示例(外部网站和同一个目录下的html都可以写进href名值对结构中):3.浏览器内显示(紫色字样表示你最近访问过,蓝色代表没有访问过):4.

    2022年7月12日
    16
  • oracle创建表空间出错的原因和解决办法「建议收藏」

    oracle创建表空间出错的原因和解决办法「建议收藏」相信很多人在创建表空间的时候遇到过这样问题.问题原因:这是因为oracle数据库是在虚拟机或者是服务器上安装的.你在本地创建文件的时候自然会找不到文件夹.就会造成图上的错误解决办法:1.打开虚拟机2.连接上oracle数据库3.找到安装oracle文件夹的位置例如:D:\oracle11g\app\oracle\oradata\4.在cmd上敲命令:createtablespacetudoudatafile‘D:\oracle11g\app\oracle\orad…

    2022年7月11日
    19
  • 深入了解zookeeper(三)

    一、ZooKeeper的实现1.1ZooKeeper处理单点故障我们知道可以通过ZooKeeper对分布式系统进行Master选举,来解决分布式系统的单点故障,如图所示。那么我们继续分析一下

    2021年12月28日
    46
  • C语言中switch语句_switch在c语言中

    C语言中switch语句_switch在c语言中本篇文章帮大家学习c语言switch语句,包含了C语言switch语句使用方法、操作技巧、实例演示和注意事项,有一定的学习价值,大家可以用来参考。C语言中的switch语句用于从多个条件执行代码。就像ifelse-if语句一样。C语言中switch语句的语法如下:switch(expression){casevalue1://codetobeexecuted;break;//opt…

    2022年8月30日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号