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 57 58 59
| #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> using namespace std;
const int N = 1010;
struct node{ int x; int y; int h; }arr[N];
int dp[1010], n;
int cmp(node a, node b){ if(a.x < b.x){ return 1; } return 0; }
int main() { freopen("input.txt", "r", stdin); int cas=1; while(scanf("%d", &n) && n) { int cur = 0; for(int i = 0; i < n; i++) { int a, b, c; scanf("%d%d%d", &a, &b, &c); arr[cur].x = min(a, b), arr[cur].y = max(a, b), arr[cur++].h = c; arr[cur].x = min(a, c), arr[cur].y = max(a, c), arr[cur++].h = b; arr[cur].x = min(b, c), arr[cur].y = max(b, c), arr[cur++].h = a; } sort(arr, arr + cur, cmp); memset(dp, 0, sizeof(dp));
for(int i = 0; i < cur; i++){ int maxs = 0; for(int j = 0; j < i; j++){ if(arr[j].x < arr[i].x && arr[j].y < arr[i].y){找出符合`x < d[i].x, y < d[i].y`的最大h和 maxs = max(maxs, dp[j]); } } dp[i] = maxs + arr[i].h; }
int maxs = dp[0]; for(int i = 0; i < cur; i++){ if(dp[i] > maxs) maxs = dp[i]; } printf("Case %d: maximum height = %d\n",cas++, maxs); } return 0; }
|