//2630234 2011-08-16 20:29:30 Accepted 1093 C++ 0 180 ylwh@Unknown
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define N 31
struct node
{
int x, y, z;
}s[N*3];
int cmp(struct node a, struct node b)
{
if(a.x != b.x)
return a.x < b.x;
else if(a.y != b.y)
return a.y <b.y;
}
int main()
{
int n, i, j, t=0, cnt, a, b, c, h[3*N], ans;
while(scanf("%d", &n), n)
{
cnt = -1;
t++;
for(i=0; i<n; i++)
{
scanf("%d%d%d", &a, &b, &c);
s[++cnt].x = a < b ? a : b;
s[cnt].y = a > b ? a : b;
s[cnt].z = c;
s[++cnt].x = a < c ? a : c;
s[cnt].y = a > c ? a : c;
s[cnt].z = b;
s[++cnt].x = b < c ? b : c;
s[cnt].y = b > c ? b : c;
s[cnt].z = a;
}
sort(s, s+cnt+1, cmp);
ans = 0;
for(i=0; i<=cnt; i++)
{
h[i] = s[i].z;
for(j=0; j<i; j++)
if(s[j].x < s[i].x && s[j].y < s[i].y)
if(h[j] + s[i].z > h[i])
h[i] = h[j] + s[i].z;
if(h[i] > ans)
ans = h[i];
}
printf("Case %d: maximum height = %d\n", t, ans);
}
return 0;
}
ZOJ 1093 Monkey and Banana【DP】
最新推荐文章于 2019-07-09 22:29:42 发布