标签:
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; struct node{ int x,y,z; }que[200]; int dp[200]; int tot; void addedge(int x,int y,int z){ que[tot].x=x; que[tot].y=y; que[tot++].z=z; que[tot].x=x; que[tot].y=z; que[tot++].z=y; que[tot].x=y; que[tot].y=x; que[tot++].z=z; que[tot].x=y; que[tot].y=z; que[tot++].z=x; que[tot].x=z; que[tot].y=x; que[tot++].z=y; que[tot].x=z; que[tot].y=y; que[tot++].z=x; } bool cmp(struct node t1,struct node t2){ if(t1.x!=t2.x) return t1.x>t2.x; else if(t1.x==t2.x&&t1.y!=t2.y) return t1.y>t2.y; else return t1.z>t2.z; } int main(){ int n; int cas=1; while(scanf("%d",&n)!=EOF){ if(!n) break; memset(dp,0,sizeof(dp)); tot=1; int x,y,z; for(int i=0;i<n;i++){ scanf("%d%d%d",&x,&y,&z); addedge(x,y,z); } sort(que+1,que+tot+1,cmp); dp[1]=que[1].z; for(int i=2;i<tot;i++){ dp[i]=que[i].z; for(int j=i-1;j>=1;j--){ if(que[i].x<que[j].x&&que[i].y<que[j].y&&dp[i]<dp[j]+que[i].z) dp[i]=dp[j]+que[i].z; } } int ans=-1; for(int i=1;i<tot;i++) ans=max(ans,dp[i]); printf("Case %d: maximum height = %d\n",cas++,ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/5351815.html