标签:des style blog http io color os ar java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7854 Accepted Submission(s): 4051
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define max(a,b) ((a)>(b)?(a):(b)) #define N 100100 struct Rect { int x,y,z; bool operator <(const Rect &t)const { if(x!=t.x) return x<t.x; return y<t.y; } }s[N]; int main() { int dp[N]; //dp[i]表示以第i个长方体结尾的最大高度 int n,i,j,m,iCase=0; while(scanf("%d",&m),m) { n=0; memset(dp,0,sizeof(dp)); while(m--) { int x,y,z; scanf("%d%d%d",&x,&y,&z); s[++n].x=x;s[n].y=y;s[n].z=z; if(s[n].x<s[n].y) swap(s[n].x,s[n].y); s[++n].x=x;s[n].y=z;s[n].z=y; if(s[n].x<s[n].y) swap(s[n].x,s[n].y); s[++n].x=z;s[n].y=y;s[n].z=x; if(s[n].x<s[n].y) swap(s[n].x,s[n].y); } sort(s+1,s+n+1); for(i=1;i<=n;i++) { dp[i]=s[i].z; for(j=1;j<i;j++) { if(s[i].x>s[j].x && s[i].y>s[j].y) dp[i]=max(dp[i],dp[j]+s[i].z); } } int ans=-1; for(i=1;i<=n;i++) { ans=max(ans,dp[i]); } printf("Case %d: maximum height = %d\n",++iCase,ans); } return 0; }
DP [HDU 1069] Monkey and Banana
标签:des style blog http io color os ar java
原文地址:http://www.cnblogs.com/hate13/p/4060048.html