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. 谈谈TCP的四次挥手

    “挥手”是为了终止连接,TCP四次挥手的流程图如下: (在socket编程中,可以由客户端或服务端进行close操作来进行) 下面的图是由客户端主动关闭连接 MSL是什么?最长报文段寿命 ------ ...

  2. Java中的List接口特有的方法

    import java.util.ArrayList; import java.util.List; /* List接口中特有方法: 添加 add(int index, E element) addA ...

  3. 监控电脑CPU,内存,文件大小,硬盘空间,IP,用户名

    public class MonitorTools { /// <summary> /// 获取具体进程的内存,线程等参数情况 /// </summary> /// <p ...

  4. redis的一个bug

    清楚redis缓存的时候,出现以下问题: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not ...

  5. [vijos]P1514 天才的记忆

    背景 神仙飞啊飞 描述 从前有个人名叫W and N and B,他有着天才般的记忆力,他珍藏了许多许多的宝藏.在他离世之后留给后人一个难题(专门考验记忆力的啊!),如果谁能轻松回答出这个问题,便可以 ...

  6. 【莫队】bzoj4542: [Hnoi2016]大数

    挺有意思的,可以仔细体味一下的题:看白了就是莫队板子. Description 小 B 有一个很大的数 S,长度达到了 N 位:这个数可以看成是一个串,它可能有前导 0,例如00009312345.小 ...

  7. Golang tcp转发 remoteAddr错误

    Golang tcp 转发 第一版本 accept获取的Conn里的localAddr做为源地址,remoteAddr来做为目的地址 // tcpForward package main import ...

  8. 【Python学习之六】高阶函数2(map、reduce、filter、sorted)

    3.filter filter()也接收一个函数和一个序列.和map()不同的是,filter()把传入的函数依次作用于每个元素,然后根据返回值是True还是False决定保留还是丢弃该元素.相当于一 ...

  9. 无法重启ssh

    rm /dev/null mknod /dev/null c 1 3 chmod 666 /dev/null

  10. 如何使用jmeter做关联

    1.适用场景 从上一个接口的返回值中获取值传递给下一个接口使用 2.添加JSON Extractor 在需求提取的参数上添加--后置处理器--JSON Extractor 从登录接口的返回值中取use ...