计蒜客:islands 打炉石传说

 AC代码:

#include<iostream>
#define MAX 100
using namespace std;
struct d
{
	int cost;
	int d;
	int w;
}card[MAX],temp[MAX];
int search_for_max(struct d *temp,int count);
int main()
{
	int i,j; 
	int n,cost,d,w;
	int monster,magic;
	cin>>n; 
	for(i=0;i<n;i++)
	{
		cin>>card[i].cost>>card[i].d>>card[i].w;
		
	}
	int count=0,sum,max=-99999;
	for(i=0;i<(1<<n);i++)
	{
		sum=0;
		count=0;
		for(j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				sum+=card[j].cost;
				temp[count]=card[j];
			//	cout<<" cost , d , w : "<<temp[count].cost<<" "<<temp[count].d <<" "<<temp[count].w ; 
				count++;
			}
		}
	
		if(sum <= 10)
		{
			if(search_for_max(temp,count)>max)
			{
				max = search_for_max(temp,count);
 			}
		}	
	//cout<<endl<<" max = "<<max<<endl;
		for(j=0;j<count;j++)
		{
			temp[j].cost = -999;
			temp[j].d =-999;
			temp[j].w =-999;
		}
	}
	cout<<max;
	return 0;
 } 
 int search_for_max(struct d *temp,int count)
 {
 	int i,index1=0,index2=0;
 	int sum=0;
 	int card_monster[MAX],card_magic[MAX];
 	for(i=0;i<count;++i)
 	{
 		if(temp[i].d==0)
 		{
 			card_monster[index1++]=temp[i].w;
		}
		else
		{
		 	card_magic[index2++]=temp[i].w;
		}
	 }
	// cout<<" index1 = "<<index1;
	 if(index1==0)
	 {
	 	return 0;
	 }
	 else
	 {
	 	sum=0;
	    for(i=0;i<count;i++)
	    {
	    //	cout<<" temp[i].w = "<<temp[i].w ;
		 	sum += temp[i].w;
		}
		//cout<<" sum = "<<sum<<endl;
		return sum;	
	 }
 }

猜你喜欢

转载自blog.csdn.net/qq_42580577/article/details/86663895