注意,每个物块都可以使用多次!
附代码:(AC,15ms)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MAX =1e4;
const int INF = 0x7f7f7f7f;
struct rec{
int x, y, z;
}a[MAX];
bool cmp(rec a, rec b){
return a.x < b.x;
}
int dp[MAX];
int main(){
int n, cnt, ca = 1;
while(~scanf("%d", &n) && n){
int cnt = 0, tp[3], ans = 0;
for(int i = 0; i < n; i++){
scanf("%d%d%d", tp, tp + 1, tp + 2);
sort(tp, tp + 3);
a[cnt].x = *tp, a[cnt].y = *(tp + 1), a[cnt++].z = *(tp + 2);
a[cnt].x = *tp, a[cnt].y = *(tp + 2), a[cnt++].z = *(tp + 1);
a[cnt].x = *(tp + 1), a[cnt].y = *(tp + 2), a[cnt++].z = *tp;
}
sort(a, a + cnt, cmp);
for(int i = 0; i < cnt; i++)
dp[i] = a[i].z;
for(int i = 0; i < cnt; i++){
int max = 0;
for(int j = i - 1; j >= 0; j--){
if(a[j].x < a[i].x && a[j].y < a[i].y)
max = max > dp[j] ? max : dp[j];
}
dp[i] += max;
ans = ans > dp[i] ? ans : dp[i];
}
printf("Case %d: maximum height = %d\n", ca++, ans);
}
}