码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1069 Monkey and Banana

时间:2018-01-28 22:02:14      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:nod   mon   scan   amp   size   case   while   height   bool   

思考:这道题真的印证了虎爷的话,最开始我还以为需要二维才能进行维护,看了题解以后才发现定义的状态一维就够了,不需要那么多

代码:

#include <bits/stdc++.h>
using namespace std;

struct node{int x,y,z;}a[1005];
int dp[1005];

bool cmp(node a,node b)
{
    if(a.x==b.x){
        if(a.y==b.y)
            return a.z<b.z;
        return a.y<b.y;
    }
    return a.x<b.x;
}
int main()
{
    int n,cas=1;
    while(~scanf("%d",&n)&&n){
        for(int i=0;i<n;i++){
            int t1,t2,t3;
            scanf("%d%d%d",&t1,&t2,&t3);
            a[i*6].x=t1,a[i*6].y=t2,a[i*6].z=t3;
            a[i*6+1].x=t1,a[i*6+1].y=t3,a[i*6+1].z=t2;
            a[i*6+2].x=t2,a[i*6+2].y=t1,a[i*6+2].z=t3;
            a[i*6+3].x=t2,a[i*6+3].y=t3,a[i*6+3].z=t1;
            a[i*6+4].x=t3,a[i*6+4].y=t1,a[i*6+4].z=t2;
            a[i*6+5].x=t3,a[i*6+5].y=t2,a[i*6+5].z=t1;
        }
        n*=6;
        sort(a,a+n,cmp);
        memset(dp,0,sizeof(dp));
        int maxe;
        for(int i=0;i<n;i++){
            maxe=0;
            for(int j=0;j<i;j++){
                if(a[j].x<a[i].x&&a[j].y<a[i].y)
                    maxe=max(maxe,dp[j]);
            }
            dp[i]=a[i].z+maxe;
        }
        maxe=-1;
        for(int i=0;i<n;i++){
            maxe=max(maxe,dp[i]);
        }
        printf("Case %d: maximum height = %d\n",cas++,maxe);
    }
    return 0;
}

 

hdu 1069 Monkey and Banana

标签:nod   mon   scan   amp   size   case   while   height   bool   

原文地址:https://www.cnblogs.com/lalalatianlalu/p/8372324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!