1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| #include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1010;
int n;
int a[N], b[N], c[N];// a,b为底,c为高
bool g[N][N];
int f[N]; // f[i]:以i为底能放最大的高度
// i能放到j的下面则true
bool judge(int i, int j) {
if (a[i] > a[j] && b[i] > b[j]) return true;
if (a[i] > b[j] && b[i] > a[j]) return true;
return false;
}
void graph() {
for (int i = 1; i <= 3 * n; i++)
for (int j = 1; j <= 3 * n; j++)
g[i][j] = judge(i, j);
}
int dp(int u) {
if (f[u]) return f[u];
f[u] = c[u];
for (int i = 1; i <= 3 * n; i++) {
if (g[u][i])
f[u] = max(f[u], c[u] + dp(i));
}
return f[u];
}
int main() {
int T = 1;
while (cin >> n, n) {
for (int i = 1; i <= 3 * n; i += 3) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
a[i] = x, b[i] = y, c[i] = z;
a[i + 1] = y, b[i + 1] = z, c[i + 1] = x;
a[i + 2] = z, b[i + 2] = x, c[i + 2] = y;
}
graph();
int ans = 0;
for (int i = 1; i <= 3 * n; i++) {
memset(f, 0, sizeof f);
ans = max(ans, dp(i));
}
printf("Case %d: maximum height = %d\n", T++, ans);
}
return 0;
}
|