就是找最高递减子序列。排下序就好。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<queue>
#include<map>
using namespace std;
#define INF 0x7fffffff
struct node{
int x,y,z;
}num[333];
int countt;
void addnum(int x,int y,int z){
num[countt].x=x;
num[countt].y=y;
num[countt++].z=z;
}
int cmp(const node &a,const node &b){
if(a.x!=b.x)
return a.x>b.x;
else{
if(a.y!=b.y)
return a.y>b.y;
else
return a.z>b.z;
}
}
int dp[333];
int main()
{
// freopen("G://test.txt","r",stdin);
int n,m,tt=0;
int i,j,mmmax;
while(scanf("%d",&n)!=EOF,n){
tt++;
countt=1;
for(int i=1;i<=n;++i){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
addnum(x,y,z);
addnum(x,z,y);
addnum(y,x,z);
addnum(y,z,x);
addnum(z,x,y);
addnum(z,y,x);
}
sort(num+1,num+countt,cmp);
for(int i=1;i<=countt;++i)
dp[i]=num[i].z;
for(int i=1;i<=countt;++i){
for(int j=1;j<i;++j){
if(num[i].x<num[j].x&&num[i].y<num[j].y){
dp[i]=max(dp[i],dp[j]+num[i].z);
}
}//for
}//for
int maxn=0;
for(int i=1;i<=countt;++i)
if(dp[i]>maxn)
maxn=dp[i];
printf("Case %d: maximum height = %d\n",tt,maxn);
}
return 0;
}