每一种箱子都有6种情况,没两个边都可以当底面,另一个边做高。排序后找面积符合情况下的高度最长上升子序列即可。
// File Name: UVa437.cpp
// Author: Toy
// Created Time: 2013年05月03日 星期五 18时20分12秒
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cctype>
#include <cmath>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <utility>
#include <bitset>
#define L(x) x << 1
#define R(x) x << 1 | 1
const int MAX = 35;
using namespace std;
struct DP {
int x, y, z;
}dp[MAX * 6];
int Case, opt[MAX * 6], cnt, a, b, c, k, i;
bool cmp ( DP a, DP b ) {
if ( a.x == b.x ) return a.y > b.y;
else return a.x > b.x;
}
int main ( ) {
cnt = 1;
while ( scanf ( "%d", &Case ) == 1 && Case ) {
memset ( opt, 0, sizeof ( opt ) );
for ( k = i = 0; i < Case; ++i ) {
scanf ( "%d%d%d", &a, &b, &c );
dp[k].x = a, dp[k].y = b, dp[k].z = c, ++k;
dp[k].x = a, dp[k].y = c, dp[k].z = b, ++k;
dp[k].x = b, dp[k].y = a, dp[k].z = c, ++k;
dp[k].x = b, dp[k].y = c, dp[k].z = a, ++k;
dp[k].x = c, dp[k].y = a, dp[k].z = b, ++k;
dp[k].x = c, dp[k].y = b, dp[k].z = a, ++k;
}
sort ( dp, dp + k, cmp );
opt[0] = dp[0].z;
for ( int i = 1; i < k; ++i ) {
int ans = 0;
for ( int j = i - 1; j >= 0; --j )
if ( dp[j].x > dp[i].x && dp[j].y > dp[i].y && opt[j] > ans ) ans = opt[j];
opt[i] = ans + dp[i].z;
}
int Max = 0;
for ( int i = 0; i < k; ++i )
if ( Max < opt[i] ) Max = opt[i];
printf ( "Case %d: maximum height = %d\n", cnt++, Max );
}
return 0;
}