Babs' Box Boutique

又是好久不刷题,然后来做contest的节奏,好多函数和算法都忘了,这题是明显的暴力题,dfs挂起。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
int vis[11],n,Max;
struct node
{
	int x,y,z;
}tr[11];
int dfs(int a,int b,int k)
{
	if(k>Max)
		Max=k;
	for(int i=0;i<n;i++)
	{
		if(!vis[i])
		{
			if(tr[i].x<=a&&tr[i].y<=b)
			{
				vis[i]=1;
				dfs(tr[i].x,tr[i].y,k+1);
			}
			if(tr[i].x<=a&&tr[i].z<=b)
			{
				vis[i]=1;
				dfs(tr[i].x,tr[i].z,k+1);
			}
			if(tr[i].y<=a&&tr[i].z<=b)
			{
				vis[i]=1;
				dfs(tr[i].y,tr[i].z,k+1);
			}
			vis[i]=0;
		}
	}
}
int main(void)
{
	int num;
	num=0;
	while(scanf("%d",&n),n!=0)
	{
		num++;
		for(int i=0;i<n;i++)
		{
			int t[3];
			scanf("%d%d%d",&t[0],&t[1],&t[2]);
			sort(t,t+3);
			tr[i].x=t[0];
			tr[i].y=t[1];
			tr[i].z=t[2];
		}
		Max=0;
		memset(vis,0,sizeof(vis));
		dfs(20,20,0);
		printf("Case %d: %d\n",num,Max);
	}
}


 

你可能感兴趣的:(Babs' Box Boutique)