To Miss Our Children Time

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 4740    Accepted Submission(s):
1319

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
 
题意:堆长方体,一共三种类型的长方体,0型号的长方体必须堆在长和宽都小于等于本身的长方体之上,1型号的长方体必须堆在长或者宽小于等于它本身的长方体之上,也就是说在其下面的长方体必有长或宽中一者是小于该长方体的。2型号的长方体必须堆在长和宽都完全小于其本身的长方体之上。满足上述条件,求能堆多高。
思路:先排好序,让长和宽数值比较大的长方体尽量先堆。这样排在队列前面的长方体肯定比排在后面的长方体先开始堆,递推,可以利用dp。
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int N_MAX = + ;
ll dp[N_MAX];
int n;
struct Cube {
ll w, l,h;
int id;
bool operator <(const Cube&b) {
if (this->l != b.l)return this->l < b.l;
else if(this->w!=b.w) return this->w < b.w;
else return this->id > b.id;
}
}cube[N_MAX]; bool judge(const Cube& a,const Cube& b) {//b要堆在a上面
if (b.id == )return b.l >= a.l&&b.w >= a.w;
if (b.id == )return (b.l >= a.l&&b.w > a.w) || (b.l > a.l&&b.w >= a.w);
return b.l > a.l&&b.w > a.w;
} void Dp() {
for (int i = ; i < n;i++) {
dp[i] = cube[i].h;
}
for (int i = ; i < n;i++) {//每次cube[i]要堆在最上面
for (int j = ; j < i;j++) {
if (judge(cube[j], cube[i]))dp[i] = max(dp[i], dp[j] + cube[i].h);
}
}
ll sum = *max_element(dp, dp + n);
printf("%I64d\n",sum);
} int main() {
while (scanf("%d",&n)&&n) {
for (int i = ; i < n;i++) {
scanf("%I64d%I64d%I64d%d",&cube[i].l,&cube[i].w,&cube[i].h,&cube[i].id);
if (cube[i].l < cube[i].w)swap(cube[i].l, cube[i].w);
}
sort(cube, cube + n);
Dp();
}
return ;
}
 

poj 4001 To Miss Our Children Time的更多相关文章

  1. hdu 4001 To Miss Our Children Time( sort + DP )

    To Miss Our Children Time Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Jav ...

  2. HDU 4001 To Miss Our Children Time(2011年大连网络赛 A 贪心+dp)

    开始还觉得是贪心呢... 给你三类积木叫你叠楼房,给你的每个积木包括四个值:长 宽(可以互换) 高 类型d d=0:你只能把它放在地上或者放在 长 宽 小于等于 自己的积木上面 d=1:你只能把它放在 ...

  3. poj 2438 Children's Dining

    http://poj.org/problem?id=2438 题意: 有2*N个人要坐在一张圆桌上吃饭,有的人之间存在敌对关系,安排一个座位次序,使得敌对的人不相邻. 假设每个人最多有N-1个敌人.如 ...

  4. POJ 3083 -- Children of the Candy Corn(DFS+BFS)TLE

    POJ 3083 -- Children of the Candy Corn(DFS+BFS) 题意: 给定一个迷宫,S是起点,E是终点,#是墙不可走,.可以走 1)先输出左转优先时,从S到E的步数 ...

  5. poj 3083 Children of the Candy Corn

    点击打开链接 Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8288 ...

  6. Children of the Candy Corn 分类: POJ 2015-07-14 08:19 7人阅读 评论(0) 收藏

    Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10933   Acce ...

  7. poj 3083 Children of the Candy Corn(DFS+BFS)

    做了1天,总是各种错误,很无语 最后还是参考大神的方法 题目:http://poj.org/problem?id=3083 题意:从s到e找分别按照左侧优先和右侧优先的最短路径,和实际的最短路径 DF ...

  8. POJ 3083 Children of the Candy Corn bfs和dfs

      Children of the Candy Corn Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8102   Acc ...

  9. POJ:3083 Children of the Candy Corn(bfs+dfs)

    http://poj.org/problem?id=3083 Description The cornfield maze is a popular Halloween treat. Visitors ...

随机推荐

  1. ovx openVirtex的阅读文档

    由于flowvisor只有4个版本, 最新更新都是2013年的, 跟底层ovs版本不跟进, 最近斯坦福post一个 ovx, 猜测是flowvisor的加强版, 所以看一下文档说明 文档详见http: ...

  2. 在无TNS配置时,登录到数据库。

    sqlplus user/pw@ip:port/servicename sqlplus user/pwd@tnsname sqlplus user/pwd---aix sqlplus /nolog&g ...

  3. MATLAB编程技巧

    [摘要] MATLAB是一种科学计算语言,和C.Fortran等高级语言相类似,能方便的实现程序控制.以下介绍一点matlab编程的技巧. 嵌套计算 程序执行的速度取决于调用的子程序的个数和算法实现. ...

  4. NOIP模拟赛 无线通讯网

    [题目描述] 国防部计划用无线网络连接若干个边防哨所.2种不同的通讯技术用来搭建无线网络:每个边防哨所都要配备无线电收发器:有一些哨所还可以增配卫星电话. 任意两个配备了一条卫星电话线路的哨所(两边都 ...

  5. 【贪心 哈夫曼树】bzoj2923: [Poi1998]The lightest language

    失去了以前用STL乱搞的能力…… 题目描述 语言也是数学上经常研究的一种数据. 给出数学上关于语言的如下定义: 字母表:大小为 K 的字母表是一个由 K 不同的字符组成的集合. 单词:长度为 m 的单 ...

  6. HUD:4405-Aeroplane chess(期望飞行棋)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...

  7. 笔记-python-centos环境下安装配置

    笔记-python-centos环境下安装配置 1.      准备工作 环境准备 centos6.5 mini,已有python 2.6.6 下载源码包 Python官网下载Gzipped sour ...

  8. HTTP认证之摘要认证——Digest(二)

    导航 HTTP认证之基本认证--Basic(一) HTTP认证之基本认证--Basic(二) HTTP认证之摘要认证--Digest(一) HTTP认证之摘要认证--Digest(二) 在HTTP认证 ...

  9. Linux学习-Linux 主机上的用户讯息传递

    查询使用者: w, who, last, lastlog 如果你想要知道目前已登入在系统上面的用户呢?可以透过 w 或 who 来查询喔!如下范例所示: [root@study ~]# w 01:49 ...

  10. shell批量修改文件名

    [root@localhost file1]# ls a.htm b.htm c.htm d.htm pl.sh [root@localhost file1]# vi pl.sh #!/bin/bas ...