Longest ascent sequence variant
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Const intmaxn= +;structx{intx, Y, Z;} S[MAXN];intN,tot;intDP[MAXN];BOOLcmpConstX&a,Constx&b) { returnA.x>b.x;}intMain () {intt=1; while(~SCANF ("%d",&N)) {if(!n) Break; Tot=0; for(intI=1; i<=n; i++) { intx, Y, Z scanf ("%d%d%d",&x,&y,&z); s[tot].x=x;s[tot].y=y;s[tot++].z=Z; s[tot].x=x;s[tot].y=z;s[tot++].z=y; s[tot].x=y;s[tot].y=x;s[tot++].z=Z; s[tot].x=y;s[tot].y=z;s[tot++].z=x; s[tot].x=z;s[tot].y=x;s[tot++].z=y; s[tot].x=z;s[tot].y=y;s[tot++].z=x; } sort (S,s+tot,cmp); Memset (DP,0,sizeofDP); for(intI=0; i<tot;i++) { intmax=-1; for(intj=0; j<i;j++) if(s[i].x<s[j].x&&s[i].y<s[j].y)if(dp[j]>Max) Max=Dp[j]; Dp[i]=max (0, Max) +s[i].z; } intans=-1; for(intI=0; i<tot;i++) ans=Max (ans,dp[i]); printf ("Case %d:maximum height =%d\n", t++, ans); } return 0;}
HDU 1069 Monkey and Banana