zoukankan      html  css  js  c++  java
  • HDOJ(1069)最长下降子序列

    每个箱子可有3种叠加方式,所以有3*n个箱子。将箱子按长度由大到小排序,有求箱子按宽度的最长下降子序列的高度之和即可。

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    #define MAX(a,b) (a>b)?a:b
    #define MIN(a,b) (a>b)?b:a
    const int SIZE=100+6;//尽量大一些; 
    struct node{
        int l;
        int w;
        int h;
    };
    node box[3*SIZE];
    
    bool comp(node no1, node no2)
    {
        return no1.l > no2.l;
    }
    int main()
    {
        int n;
        int t=0;
        while(scanf("%d",&n)!=EOF&&n!=0)
        {
            for(int i=0;i<n;i++)
            {
                int x,y,z;
                scanf("%d %d %d",&x,&y,&z);
                box[i*3+0].h=x;box[i*3+0].l=MAX(y,z);box[i*3+0].w=MIN(y,z);
                box[i*3+1].h=y;box[i*3+1].l=MAX(x,z);box[i*3+1].w=MIN(x,z);
                box[i*3+2].h=z;box[i*3+2].l=MAX(y,x);box[i*3+2].w=MIN(y,x);
            }
            
            sort(box,box+3*n,comp);
            
            int ans=-1;
            int h[SIZE];
            memset(h,0,sizeof(h));
            for(int i=0;i<3*n;i++)
            {
                h[i]=box[i].h;
                for(int j=0;j<i;j++)
                {
                    if(box[i].w<box[j].w&&box[i].l<box[j].l)
                    {
                        h[i]=MAX(h[j]+box[i].h,h[i]);
                    }
                }
                ans=MAX(h[i],ans);
            }
            printf("Case %d: maximum height = %d
    ",++t,ans);
        }
        
        return 0;
    }
  • 相关阅读:
    Vue Router基础
    Bootstrap4入门
    React性能优化
    Koa,React和socket.io
    RN-进阶
    RN-入门基础
    RN-环境配置
    React高级指引
    React基础概念
    实现A-Z滑动检索菜单
  • 原文地址:https://www.cnblogs.com/program-ccc/p/4695244.html
Copyright © 2011-2022 走看看