题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1069
由于箱子个数是无限的,所以每一个箱子相当于六个箱子,我们只关心高度,长宽一开始就设定好,就变成3个箱子了。
排序后,dp(i)=max(dp(i),dp(j)+h(i))
1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 using namespace std; 36 #define fr first 37 #define sc second 38 #define cl clear 39 #define BUG puts("here!!!") 40 #define W(a) while(a--) 41 #define pb(a) push_back(a) 42 #define Rint(a) scanf("%d", &a) 43 #define Rs(a) scanf("%s", a) 44 #define Cin(a) cin >> a 45 #define FRead() freopen("in", "r", stdin) 46 #define FWrite() freopen("out", "w", stdout) 47 #define Rep(i, len) for(int i = 0; i < (len); i++) 48 #define For(i, a, len) for(int i = (a); i < (len); i++) 49 #define Cls(a) memset((a), 0, sizeof(a)) 50 #define Clr(a, x) memset((a), (x), sizeof(a)) 51 #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) 52 #define lrt rt << 1 53 #define rrt rt << 1 | 1 54 #define pi 3.14159265359 55 #define RT return 56 #define lowbit(x) x & (-x) 57 #define onecnt(x) __builtin_popcount(x) 58 typedef long long LL; 59 typedef long double LD; 60 typedef unsigned long long ULL; 61 typedef pair<int, int> pii; 62 typedef pair<string, int> psi; 63 typedef pair<LL, LL> pll; 64 typedef map<string, int> msi; 65 typedef vector<int> vi; 66 typedef vector<LL> vl; 67 typedef vector<vl> vvl; 68 typedef vector<bool> vb; 69 70 typedef struct Node { 71 int a, b, c; 72 Node() {} 73 Node(int aa, int bb, int cc) : a(aa), b(bb), c(cc) {} 74 }Node; 75 76 const int maxn = 55; 77 int n, m; 78 int dp[maxn*10]; 79 Node box[maxn*10]; 80 81 bool cmp(Node x, Node y) { 82 return x.a > y.a; 83 } 84 85 Node add(int a, int b, int c) { 86 if(a > b) swap(a, b); 87 return Node(a, b, c); 88 } 89 90 int main() { 91 // FRead(); 92 int a, b, c; 93 int _ = 1; 94 while(~Rint(n) && n) { 95 m = 0; 96 Rep(i, n) { 97 Rint(a); Rint(b); Rint(c); 98 box[m++] = add(a, b, c); 99 box[m++] = add(b, c, a); 100 box[m++] = add(c, a, b); 101 } 102 sort(box,box+m,cmp); 103 Cls(dp); 104 int ret = 0; 105 Rep(i, m) { 106 int tmp = 0; 107 Rep(j, i) { 108 if(box[j].b > box[i].b && box[j].a > box[i].a) { 109 tmp = max(tmp, dp[j]); 110 } 111 } 112 dp[i] = tmp + box[i].c; 113 ret = max(ret, dp[i]); 114 } 115 printf("Case %d: maximum height = %d ", _++, ret); 116 } 117 RT 0; 118 }