给你n砖,有三个长宽高。每一个无限制的访问。叠加在一个条件的长度和宽度必须严格格长度和宽度大于下面的一个,叠加求最大高度。
思维:
每块砖终于放置在根据本方法可以把六种,然后,对于长度和宽度排序。这是LIS的变化的问题
#include<iostream> #include<cstdio> #include<list> #include<algorithm> #include<cstring> #include<string> #include<queue> #include<stack> #include<map> #include<vector> #include<cmath> #include<memory.h> #include<set> #include<cctype> #define ll long long #define LL __int64 #define eps 1e-8 #define inf 0xfffffff //const LL INF = 1LL<<61; using namespace std; //vector<pair<int,int> > G; //typedef pair<int,int > P; //vector<pair<int,int> > ::iterator iter; // //map<ll,int >mp; //map<ll,int >::iterator p; int box[500][3]; int dp[1000]; int cnt; typedef struct Node { int x,y,z; }; Node node[500]; void init() { memset(box,0,sizeof(box)); memset(dp,0,sizeof(dp)); cnt = 0; } /*void cal(int x,int y,int z) { box[cnt][0] = x,box[cnt][1] = y,box[cnt++][2] = z; box[cnt][0] = y,box[cnt][1] = x,box[cnt++][2] = z; box[cnt][0] = y,box[cnt][1] = z,box[cnt++][2] = x; box[cnt][0] = z,box[cnt][1] = y,box[cnt++][2] = x; box[cnt][0] = x,box[cnt][1] = z,box[cnt++][2] = y; box[cnt][0] = z,box[cnt][1] = x,box[cnt++][2] = y; }*/ void cal(int x,int y,int z) { node[cnt].x = x,node[cnt].y = y,node[cnt++].z = z; node[cnt].x = y,node[cnt].y = x,node[cnt++].z = z; node[cnt].x = y,node[cnt].y = z,node[cnt++].z = x; node[cnt].x = z,node[cnt].y = y,node[cnt++].z = x; node[cnt].x = x,node[cnt].y = z,node[cnt++].z = y; node[cnt].x = z,node[cnt].y = x,node[cnt++].z = y; } bool cmp(Node x,Node y) { if(x.x == y.x) { if(x.y == y.y)return x.z < y.z; return x.y < y.y; } return x.x < y.x; } int main() { int n; int Case = 0; while(scanf("%d",&n),n) { init(); for(int i=0;i<n;i++) { int x,y,z; scanf("%d %d %d",&x,&y,&z); cal(x,y,z); } int ans = 0; sort(node,node+cnt,cmp); /*for(int i=0;i<cnt;i++) { printf("%d %d %d** ",node[i].x,node[i].y,node[i].z); }*/ for(int i=0;i<cnt;i++) dp[i] = node[i].z; for(int i=0;i<cnt;i++) { for(int j=1;j<i;j++) { int a = node[j].x; int b= node[i].x; int c = node[j].y; int d= node[i].y; if(node[j].x < node[i].x && node[j].y < node[i].y) { dp[i] = max(dp[j] + node[i].z,dp[i]); } } if(ans < dp[i]) ans = dp[i]; } printf("Case %d: maximum height = %d ",++Case,ans); } return 0; }