杭电ACM HDU 2616 Kill the monster

/*暴力搜索*/
#include <cstdio>
int c;//统计需要的spell的数量
int n;//spell的种类数
int m;//怪兽的血量
int spell[11][2];
void search(int b,int f[],int count,int m){
    if(b<n&&m>0){
        for(int i=0;i<n;i++){
            if(f[i])continue;//如果spell已经使用找下一个spell
            else{
				count++;
				f[i]=1;//记录为已使用
                if(spell[i][1]>=m){
                    m-=spell[i][0]*2;	
					search(b+1,f,count,m);
					m+=spell[i][0]*2;
				}
                else{
                    m-=spell[i][0];
					search(b+1,f,count,m);
					m+=spell[i][0];
				}
				f[i]=0;//恢复
				count--;
            }
        }
    }
    else if(m<=0){//如果杀死了怪物
        if(count<c)
            c=count;//记录使用的spell数量
    }
}
int main(){
    int f[11];//记录spell的使用情况,0未使用,1已使用
    //freopen("in.txt","r",stdin);
    while(~scanf("%d%d",&n,&m)){
        for(int i=0;i<n;i++){//输入数据
            scanf("%d%d",&spell[i][0],&spell[i][1]);
            f[i]=0;//初始化
        }
        c=11;
        search(0,f,0,m);
		//如果c没有改变表示不能杀死怪物
		if(c==11)c=-1;
        printf("%d\n",c);
    }
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值