首页 > 其他 > 详细

HDU 1069 Monkey and Banana

时间:2016-01-17 12:18:35      阅读:153      评论:0      收藏:0      [点我收藏+]

最长上升序列变形

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int maxn=1000;
struct X
{
    int x,y,z;
} s[maxn];
int n,tot;
int dp[maxn];

bool cmp(const X&a,const X&b)
{
    return a.x>b.x;
}

int main()
{
    int T=1;
    while(~scanf("%d",&n))
    {
        if(!n) break;
        tot=0;
        for(int i=1; i<=n; i++)
        {
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            s[tot].x=x;s[tot].y=y;s[tot++].z=z;
            s[tot].x=x;s[tot].y=z;s[tot++].z=y;
            s[tot].x=y;s[tot].y=x;s[tot++].z=z;
            s[tot].x=y;s[tot].y=z;s[tot++].z=x;
            s[tot].x=z;s[tot].y=x;s[tot++].z=y;
            s[tot].x=z;s[tot].y=y;s[tot++].z=x;
        }
        sort(s,s+tot,cmp);
        memset(dp,0,sizeof dp);
        for(int i=0;i<tot;i++)
        {
            int Max=-1;
            for(int j=0;j<i;j++)
                if(s[i].x<s[j].x&&s[i].y<s[j].y)
                    if(dp[j]>Max)
                        Max=dp[j];
            dp[i]=max(0,Max)+s[i].z;
        }
        int ans=-1;
        for(int i=0;i<tot;i++) ans=max(ans,dp[i]);
        printf("Case %d: maximum height = %d\n",T++,ans);
    }
    return 0;
}

 

HDU 1069 Monkey and Banana

原文:http://www.cnblogs.com/zufezzt/p/5136927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!