• HDU4001 To Miss Our Children Time


    HDU4001 To Miss Our Children Time

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)

    Total Submission(s): 1879    Accepted Submission(s): 514

    Problem Description

    Do you remember our children time? When we are children, we are interesting in almost everything around ourselves. A little thing or a simple game will brings us lots of happy time! LLL is a nostalgic boy, now he grows up. In the dead of night, he often misses something, including a simple game which brings him much happy when he was child. Here are the game rules: There lies many blocks on the ground, little LLL wants build "Skyscraper" using these blocks. There are three kinds of blocks signed by an integer d. We describe each block's shape is Cuboid using four integers ai, bi, ci, di. ai, bi are two edges of the block one of them is length the other is width. ci is 

    thickness of the block. We know that the ci must be vertical with earth ground. di describe the kind of the block. When di = 0 the block's length and width must be more or equal to the block's length and width which lies under the block. When di = 1 the block's length and width must be more or equal to the block's length which lies under the block and width and the block's area must be more than the block's area which lies under the block. When di = 2 the block length and width must be more than the block's length and width which lies under the block. Here are some blocks. Can you know what's the highest "Skyscraper" can be build using these blocks?

    Input

    The input has many test cases. 

    For each test case the first line is a integer n ( 0< n <= 1000) , the number of blocks. 

    From the second to the n+1'th lines , each line describing the i‐1'th block's a,b,c,d (1 =< ai,bi,ci <= 10^8 , d = 0 or 1 or 2). 

    The input end with n = 0.

    Output

    Output a line contains a integer describing the highest "Skyscraper"'s height using the n blocks.

    Sample Input

    3

    10 10 12 0

    10 10 12 1

    10 10 11 2

    2

    10 10 11 1

    10 10 11 1

    0

    Sample Output

    24

    11

    Source

    The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest

    *************************************************************************

    这是2011年大连赛区网络赛的第一道题目。当时有YYB在写了,我就没写。

    这题就是一道简单dp。先把每个木块存一下,然后按照先a从小到大,在按照b从小到大,再按照d从大到小排列。具体的状态转移方程是一样的,只是当d有差别的时候,j的取值有所不同,dp[i]=max{dp[j]+c[i]}(j是比i小的,且满足d的要求的木块)。

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    #define INF 0x3f3f3f3f
    using namespace std;
    
    long long n,dp[1005];
    struct Node
    {
        long long a,b,c,d;
    }node[1005];
    
    long long max(long long x,long long y){return x>y?x:y;}
    
    bool cmp(Node x,Node y)
    {
        if(x.a!=y.a)return x.a<y.a;
        if(x.b!=y.b)return x.b<y.b;
        return x.d>y.d;
    }
    
    int main()
    {
        while(scanf("%I64d",&n),n)
        {
            memset(node,0,sizeof(node));
            memset(dp,0,sizeof(dp));
            for(long long i=1;i<=n;i++)
            {
                scanf("%I64d%I64d%I64d%I64d",&node[i].a,&node[i].b,&node[i].c,&node[i].d);
                if(node[i].a<node[i].b)
                {
                    long long temp=node[i].a;
                    node[i].a=node[i].b;
                    node[i].b=temp;
                }
            }
            sort(node+1,node+1+n,cmp);
            node[0].a=node[0].b=0;
            node[0].c=0;
            dp[0]=0;
            for(long long i=1;i<=n;i++)
                for(long long j=i-1;j>=0;j--)
                {
                    if(node[i].d==0&&node[j].a<=node[i].a&&node[j].b<=node[i].b)
                        dp[i]=max(dp[i],dp[j]+node[i].c);
                    if(node[i].d==1&&node[j].a<=node[i].a&&node[j].b<=node[i].b&&node[j].a*node[j].b<node[i].a*node[i].b)
                        dp[i]=max(dp[i],dp[j]+node[i].c);
                    if(node[i].d==2&&node[j].a<node[i].a&&node[j].b<node[i].b)
                        dp[i]=max(dp[i],dp[j]+node[i].c);
                }
            long long maxx=-1;
            for(long long i=1;i<=n;i++)
                maxx=max(maxx,dp[i]);
            printf("%I64d\n",maxx);
        }
    }
    

      

  • 相关阅读:
    北风设计模式课程---单一职责原则
    北风设计模式课程---访问者模式(Visitor)
    北风设计模式课程---访问者(Visitor)模式
    北风设计模式课程---命令模式
    社交专题---3、装逼的那些事儿
    社交专题---2、男生的套路有多深
    MHA 日常管理
    【屌丝程序的口才逆袭演讲稿50篇】第十篇:程序猿们请看看外面的世界吧【张振华.Jack】
    Win32 Windows编程 九
    java实现大数相加问题
  • 原文地址:https://www.cnblogs.com/Fatedayt/p/2175112.html
Copyright © 2020-2023  润新知