问题: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

回答:题意大概是给你些积木,分三类,0:只能放在小于等于它的长和宽的积木上,1:只能放在长和宽小于等于它且面积小于他的木块上,2:只能放在长和宽偶小于它的木块上。求积木的最高高度。

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct block
{
    int x,y,z,d;
}b[1005];
long long dp[1005];
int n;
bool cmp(block a,block b)
{
    if(a.x!=b.x)return a.x<b.x;
    if(a.y!=b.y)return a.y<b.y;
    return a.d>b.d;
}
void DP()
{
    long long ans=b[0].z;
    for(int i=0;i<n;i++)
    {
        dp[i]=b[i].z;
        ans=max(ans,dp[i]);
    }
    for(int i=1;i<n;i++)
    {
        if(b[i].d==0)
        {
            for(int j=0;j<i;j++)
            {
                if(b[j].x<=b[i].x&&b[j].y<=b[i].y)
                    dp[i]=max(dp[i],dp[j]+b[i].z);
            }
        }
        if(b[i].d==1)
        {
            for(int j=0;j<i;j++)
            {
                if(b[j].x<=b[i].x&&b[i].y>=b[j].y&&(b[i].y*b[j].y||b[i].x>b[j].x))
                    dp[i]=max(dp[i],dp[j]+b[i].z);
            }
        }
        if(b[i].d==2)
        {
            for(int j=0;j<i;j++)
            {
                if(b[i].x>b[j].x&&b[i].y>b[j].y)
                {
                    dp[i]=max(dp[i],dp[j]+b[i].z);
                }
            }
        }
        ans=max(ans,dp[i]);  
    }
    cout<<ans<<'\n';
}

int main()
{
    while(1)
    {
        scanf("%d",&n);
        if(n==0)break;
        for(int i=0;i<n;i++)
        {
            scanf("%d%d%d%d",&b[i].x,&b[i].y,&b[i].z,&b[i].d);
            if(b[i].x<b[i].y)
                swap(b[i].x,b[i].y);
        }
        sort(b,b+n,cmp);
        DP();
    }
    return 0;
}

积木(DP)问题的更多相关文章

  1. 洛谷P5162 WD与积木 [DP,NTT]

    传送门 思路 真是非常套路的一道题-- 考虑\(DP\):设\(f_n\)为\(n\)个积木能搭出的方案数,\(g_n\)为所有方案的高度之和. 容易得到转移方程: \[ \begin{align*} ...

  2. NOI 97 (Vijos 1464)积木游戏(DP)

    很普通的DP,设dp[i][j][k]为第i块积木放在第j堆且摆放状态为k的最高高度.方程很容易推出. # include <cstdio> # include <cstring&g ...

  3. vijos 1464 积木游戏 DP

    描述 积木游戏 SERCOI 最近设计了一种积木游戏.每个游戏者有N块编号依次为1 ,2,…,N的长方体积木.对于每块积木,它的三条不同的边分别称为"a边"."b边&qu ...

  4. [NOI1997] 积木游戏(dp)

    COGS 261. [NOI1997] 积木游戏 http://www.cogs.pro/cogs/problem/problem.php?pid=261 ★★   输入文件:buildinggame ...

  5. 计蒜客习题:蒜头君的积木 (状压DP 枚举子集)

    问题描述 蒜头君酷爱搭积木,他用积木搭了 n 辆重量为 wi的小车和一艘最大载重量为 W 的小船,他想用这艘小船将 n 辆小车运输过河.每次小船运载的小车重量不能超过 W.另外,小船在运载小车时,每辆 ...

  6. power oj 2480 放积木[二进制状压DP]

    题目链接[https://www.oj.swust.edu.cn/problem/show/2480] 题意:中文题目. 题解:二进制状态转移+坏点判断. #include<cstdio> ...

  7. BZOJ.1109.[POI2007]堆积木Klo(DP LIS)

    BZOJ 二维\(DP\)显然.尝试换成一维,令\(f[i]\)表示,强制把\(i\)放到\(a_i\)位置去,现在能匹配的最多数目. 那么\(f[i]=\max\{f[j]\}+1\),其中\(j& ...

  8. 积木城堡(dp)

    题目描述 XC的儿子小XC最喜欢玩的游戏用积木垒漂亮的城堡.城堡是用一些立方体的积木垒成的,城堡的每一层是一块积木.小XC是一个比他爸爸XC还聪明的孩子,他发现垒城堡的时候,如果下面的积木比上面的积木 ...

  9. 洛谷P2409 Y的积木

    P2409 Y的积木 77通过 491提交 题目提供者zhouyonglong 标签云端评测 难度普及+/提高 提交  讨论  题解 最新讨论 这组数据几乎可以卡掉所有程- 第一个题解有点问题 求教大 ...

随机推荐

  1. 继承进一步使用,以及super关键字

    目标: 1)掌握子类对象实例化过程 2)掌握方法覆盖概念和实现. 3)掌握super关键字的作用. 一,子类对象实例化过程 子类对象在实例化之前,必须先调用父类中的构造方法,再调用子类中的构造方法. ...

  2. iOS开发——网络编程Swift篇&Alamofire详解

    Alamofire详解 预览图 Swift Alamofire 简介 Alamofire是 Swift 语言的 HTTP 网络开发工具包,相当于Swift实现AFNetworking版本. 当然,AF ...

  3. page-cache层以及各种标志位之间的转换

    对真实文件系统层,算是懂了,但是vfs层以及block层还是有点生疏呢,最近要好好分析一下了. page-cache层主要关注文件读写时的行为,包括页的状态之间的变化,何时变脏,何时变成writeba ...

  4. 21SpringMvc_异步发送表单数据到Bean,并响应JSON文本返回(这篇可能是最重要的一篇了)

    这篇文章实现三个功能:1.在jsp页面点击一个按钮,然后跳转到Action,在Action中把Emp(int id ,String salary,Data data)这个实体变成JSON格式返回到页面 ...

  5. C# winform版 nbtstat

    参考:http://www.cnblogs.com/geqinggao/archive/2013/01/21/2869644.html 一.nbtstat命令 显示基于 TCP/IP 的 NetBIO ...

  6. Studying-Swift :Day01

    学习地址:http://www.rm5u.com/    或    http://www.runoob.com/ 如果创建的是 OS X playground 需要引入 Cocoa;  如果我们想创建 ...

  7. MySQL学习指引

    mysql指引 1,mysql基本安装 2,mysql多实例安装与维护 3,备份恢复 备份数据库 分备数据库 分备表 恢复数据库

  8. 设计传说 PS零基础精通 Photoshop CC 2015视频教程

           课程目录: 课时1 Photoshop CC 2015 全面技能培训介绍  03:08课时2 1.1 PSCC工作区域及面板自定义 08:47课时3 1.2 图像文件的多种打开方式 0 ...

  9. listview向下滑动过程中背景色变成黑色和一些奇怪问题

    ListView是一个经常要用到的android控件,现总结遇到过的一些美化的小细节. 1.listview在拖动的时候背景图片消失变成黑色背景,等到拖动完毕我们自己的背景图片才显示出来 这个问题是我 ...

  10. LeetCode:Best Time to Buy and Sell Stock I II III

    LeetCode:Best Time to Buy and Sell Stock Say you have an array for which the ith element is the pric ...