标签:
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10875 Accepted Submission(s): 5660
题目:给出一些长方体,然后让你把他堆成塔,
要求下面的塔的要比上面的塔大(长和宽),
而且每一种长方体的数量都是无限的。
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N = 200; 6 7 struct Node { 8 int x; 9 int y; 10 int z; 11 bool operator < (const Node &a) const 12 { 13 if(x!=a.x) return x < a.x; 14 else if(y!=a.y) return y < a.y; 15 else return z > a.z; 16 } 17 } node[N]; 18 int dp[N]; 19 20 int main() 21 { 22 int n; 23 int cnt = 1; 24 while(~scanf("%d",&n)) 25 { 26 if(n==0) return 0; 27 memset(dp,0,sizeof(dp)); 28 int x,y,z; 29 int t = 0; 30 for(int i = 0; i < n; i++){ 31 scanf("%d%d%d",&x,&y,&z); 32 node[t].x = x; 33 node[t].y = y; 34 node[t].z = z; 35 t++; 36 node[t].x = x; 37 node[t].y = z; 38 node[t].z = y; 39 t++; 40 node[t].x = y; 41 node[t].y = x; 42 node[t].z = z; 43 t++; 44 node[t].x = y; 45 node[t].y = z; 46 node[t].z = x; 47 t++; 48 node[t].x = z; 49 node[t].y = x; 50 node[t].z = y; 51 t++; 52 node[t].x = z; 53 node[t].y = y; 54 node[t].z = x; 55 t++; 56 } 57 sort(node,node+6*n); 58 int mmax = 0; 59 for(int i = 0; i < 6*n; i++) 60 dp[i] = node[i].z; 61 for(int i = 0; i < 6*n; i++) 62 { 63 for(int j = 0; j < i; j++) 64 { 65 if((node[i].x>node[j].x)&&(node[i].y>node[j].y)) 66 dp[i] = max(dp[i],dp[j]+node[i].z); 67 } 68 mmax = max(mmax,dp[i]); 69 } 70 printf("Case %d: maximum height = ",cnt); 71 cnt++; 72 printf("%d\n",mmax); 73 } 74 return 0; 75 }
标签:
原文地址:http://www.cnblogs.com/shanyr/p/5255734.html