给你n 种长方体,每种长方体x,y,z。每个长方体都有无限个
然后用这些长方体叠起来求最高的高度。
上层的长方体x,y为xi,yi,下层的为xj,yj,要满足xi < xj && yi < yj
这样把x 或y 升序排序 就变成求最长上升子序列。然后每个长方体x,y,z,有6种组合。处理一下。
代码看着比较蛋疼0 0
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int const MAXN = 200; int dp[MAXN]; struct M{ int x,y,z; }m[MAXN]; void F(int x,int y,int z,int &cnt){ m[cnt].x = x; m[cnt].y = y; m[cnt++].z = z; m[cnt].x = y; m[cnt].y = x; m[cnt++].z = z; m[cnt].x = z; m[cnt].y = y; m[cnt++].z = x; m[cnt].x = y; m[cnt].y = z; m[cnt++].z = x; m[cnt].x = x; m[cnt].y = z; m[cnt++].z = y; m[cnt].x = z; m[cnt].y = x; m[cnt++].z = y; } bool cmp(M a,M b){ if(a.x != b.x) return a.x < b.x; return a.y < b.y; } inline int Max(int a,int b){ return a>b?a:b; } int main(){ int n; int k = 1; while(~scanf("%d",&n),n){ int cnt = 1; for(int i = 1;i <= n;i++){ int x,y,z; scanf("%d%d%d",&x,&y,&z); F(x,y,z,cnt); } sort(m+1,m+cnt,cmp); memset(dp,0,sizeof(dp)); int s = 0; for(int i = 1;i < cnt;i++){ dp[i] = m[i].z; } for(int i = 1;i < cnt;i++){ for(int j = 1;j < i;j++){ if(m[i].x > m[j].x && m[i].y > m[j].y){ dp[i] = Max(dp[i],dp[j] + m[i].z); } } //cout<<m[i].x<<" "<<m[i].y<<" "<<m[i].z<<" "<<dp[i]<<endl; s = Max(s,dp[i]); } printf("Case %d: maximum height = %d\n",k++,s); } return 0; }