标签:des style blog http color io os ar java
1 10 20 30 2 6 8 10 5 5 5 7 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 5 31 41 59 26 53 58 97 93 23 84 62 64 33 83 27 0
Case 1: maximum height = 40 Case 2: maximum height = 21 Case 3: maximum height = 28 Case 4: maximum height = 342
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 1000; 18 struct box{ 19 int width,length,height; 20 box(int x = 0,int y = 0,int z = 0){ 21 width = x; 22 length = y; 23 height = z; 24 } 25 }; 26 box b[maxn]; 27 int tot,n,dp[maxn],ans; 28 bool cmp(const box &x,const box &y){ 29 if(x.length == y.length) return x.width < y.width; 30 return x.length < y.length; 31 } 32 int main() { 33 int W,L,H,cs = 1; 34 while(scanf("%d",&n),n){ 35 for(int i = tot = 0; i < n; i++){ 36 scanf("%d %d %d",&W,&L,&H); 37 b[tot++] = box(W,L,H); 38 b[tot++] = box(L,W,H); 39 b[tot++] = box(W,H,L); 40 b[tot++] = box(H,L,W); 41 b[tot++] = box(L,H,W); 42 b[tot++] = box(H,W,L); 43 } 44 sort(b,b+tot,cmp); 45 ans = 0; 46 for(int i = 0; i < tot; i++){ 47 dp[i] = b[i].height; 48 for(int j = 0; j < i; j++){ 49 if(b[j].width < b[i].width && b[j].length < b[i].length && dp[i] < dp[j]+b[i].height){ 50 dp[i] = dp[j] + b[i].height; 51 } 52 } 53 ans = max(ans,dp[i]); 54 } 55 printf("Case %d: maximum height = %d\n",cs++,ans); 56 } 57 return 0; 58 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/crackpotisback/p/4002777.html