437

把某个立方体的六种每个都算一种即可

//============================================================================
// Name        : 437.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef struct{
	int x,y;
	int h;
}block;

block cube[300];
int num, a, b, c, Max, n;
int d[300];



bool cmp(block a, block b){
	if(a.x < b.x){
		return true;
	}
	else if(a.x == b.x){
		if(a.y < b.y){
			return true;
		}
		else if(a.y == b.y){
			if(a.h > b.h){
				return true;
			}
			else{
				return false;
			}
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
}


int main() {
	freopen("a.txt", "r", stdin);
	int T = 0;
	while(scanf("%d", &n)&&n){
		T++;
		num = 0;
		for(int i = 0;i < n;i++){
			scanf("%d%d%d", &a, &b, &c);
			cube[num].x = a;
			cube[num].y = b;
			cube[num].h = c;
			num += 1;
			cube[num].x = a;
			cube[num].y = c;
			cube[num].h = b;
			num += 1;
			cube[num].x = b;
			cube[num].y = a;
			cube[num].h = c;
			num += 1;
			cube[num].x = b;
			cube[num].y = c;
			cube[num].h = a;
			num += 1;
			cube[num].x = c;
			cube[num].y = a;
			cube[num].h = b;
			num += 1;
			cube[num].x = c;
			cube[num].y = b;
			cube[num].h = a;
			num += 1;
		}
		sort(cube, cube+num, cmp);
		Max = 0;
		for(int i = 0;i < num;i++){
			d[i] = cube[i].h;
			if(Max < d[i]){
				Max = d[i];
			}
		}
//		for(int i = 0;i < num;i++){
//			printf("%d %d %d\n", cube[i].x, cube[i].y, cube[i].h);
//			//printf("%d\n", d[i]);
//		}
//		printf("%d\n", Max);
		for(int i = 0;i < num;i++){
			for(int j = 0;j <= i;j++){
				if(cube[i].x > cube[j].x&&cube[i].y > cube[j].y){
					if(d[i] < d[j]+cube[i].h){
						d[i] = d[j]+cube[i].h;
						if(Max < d[i]){
							Max = d[i];
						}
					}
				}
			}
		}
		printf("Case %d: maximum height = ", T);
		printf("%d\n", Max);
	}
	return 0;
}

  

posted @ 2011-07-28 14:41  KOKO's  阅读(146)  评论(0编辑  收藏  举报