nyoj 232

长和宽按降序排列,最后找出最长降序子序列;

 

#include 
#include 
#include 
#include 

using namespace std;

const int MAXN = 100;

struct Edge_Of_Rectangle
{
	int length;
	int wide;
	int high;
}Rec[MAXN];

int MAX(int a, int b)
{
	return a > b ? a : b;
}

void Swap(int &a, int &b, int &c)
{
	if(a > b)
	{
		a ^= b;
		b ^= a;
		a ^= b;
	}
	if(a > c)
	{
		a ^= c;
		c ^= a;
		a ^= c;
	}
	if(b > c)
	{
		b ^= c;
		c ^= b;
		b ^= c;
	}
}

int CMP(const void *a, const void *b)
{
	Edge_Of_Rectangle* aa = (Edge_Of_Rectangle *)a;
	Edge_Of_Rectangle* bb = (Edge_Of_Rectangle *)b;

	if(aa->length == bb->length)
		return bb->wide - aa->wide;
	else
		return bb->length - aa->length;
}


int main()
{
	int n;
	int i, j, tmp;
	int x, y, z;
	int dp[MAXN];
	int kcase = 1;
	while (scanf("%d", &n), n)
	{
		memset(dp, 0, sizeof(dp));
		tmp = 0;
		for (i = 0; i < n; ++i)
		{
			scanf("%d %d %d", &x, &y, &z);

			Swap(x, y, z);
			//cout<<"******"< Rec[i].length && Rec[j].wide > Rec[i].wide)
					dp[i] = MAX(dp[i], dp[j] + Rec[i].high);
			}
			if(dp[i] > ans)
				ans = dp[i];
		}
		printf("Case %d: maximum height = %d\n", kcase++, ans);
	}
	return 0;
}

 

 

 

 

 

你可能感兴趣的:(Nyoj,DP,ACM)