UVa 437 - The Tower of Babylon

每一种箱子都有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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值