相当于最长上升子序列 由于每个木块的数量是很多,最多用一块 我们只要枚举长宽高的六种情况 然后进行排序  利用最长上升子序列的方法 就可以,这个题不用输出路径,所以比较简单

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

struct dat
{
    int nx, ny,nz;
    void f(int a, int b, int c)
    {
        nx=a;
        ny=b;
        nz=c;
    }
    bool operator <(const dat p) const
    {
        if(nx!=p.nx)
            return p.nx<nx;
        if(ny!=p.ny)
            return p.ny<ny;
        return p.nz<nz;
    }
} a[210];
int n;
long long dp[220];
int main()
{
    int cas=0;
    while(scanf("%d",&n)==1 && n)
    {
        int x,y,z;
        int m=0;
        for(int i=0; i<n; i++)
        {
            scanf("%d %d %d",&x,&y,&z);
            a[m++].f(x,y,z);
            a[m++].f(x,z,y);
            a[m++].f(y,x,z);
            a[m++].f(y,z,x);
            a[m++].f(z,x,y);
            a[m++].f(z,y,x);
        }
        long long mx=-1;
        memset(dp, 0, sizeof(dp));
        int ma;
        sort(a, a+m);
        dp[0]=a[0].nz;
        for(int i=1; i<m; i++)
        {
            ma=0;
            for(int j=0; j<i; j++)
            {
                if(a[i].nx<a[j].nx && a[i].ny<a[j].ny && ma<dp[j])
                    ma=dp[j];
            }
            dp[i]=ma+a[i].nz;
            if(mx<dp[i])
                mx=dp[i];
        }
        cas++;
        printf("Case %d: maximum height = %lld\n",cas,mx);
    }
    return 0;
}
View Code

 

posted on 2013-08-15 09:34  风流monkey  阅读(203)  评论(0编辑  收藏  举报