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. JS实用技术

    JS外部引用其他文件(建议) <script src="myScript1.js"></script> JS输出显示方式 使用 window.alert() ...

  2. Bootstrap历练实例:默认的进度条

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. CentOS 编译安装PHP5.6(7以上也通用)

    由于公司有新服务器需要构建一套LNMP平台,且需要编译安装各个部件,所以记录下此文章. 这是安装PHP涉及到的软件包(可以自行决定使用哪个版本): ├── libiconv-1.15.tar.gz ├ ...

  4. c++ 函数指针应用,定义一个方法,传入两个参数和一个函数指针,并返回结果

    #include <iostream> #include <string> using namespace std; double add(double x, double y ...

  5. NOIP模拟赛 经营与开发 小奇挖矿

    [题目描述] 4X概念体系,是指在PC战略游戏中一种相当普及和成熟的系统概念,得名自4个同样以“EX”为开头的英语单词. eXplore(探索) eXpand(拓张与发展) eXploit(经营与开发 ...

  6. $GLOBALS['HTTP_RAW_POST_DATA']与$_POST的区别

    $HTTP_RAW_POST_DATA   The RAW / uninterpreted HTTP POst information can be accessed with:   $GLOBALS ...

  7. H5(一)H5与HTML、XHTML的不同

    一.基本概念 html:超文本标记语言 (Hyper Text Markup Language) xhtml:可扩展超文本标记语言,是一种置标语言,表现方式与超文本标记语言(HTML)类似,不过语法上 ...

  8. LeetCode1089复写零

    问题: 给你一个长度固定的整数数组 arr,请你将该数组中出现的每个零都复写一遍,并将其余的元素向右平移. 注意:请不要在超过该数组长度的位置写入元素. 要求:请对输入的数组 就地 进行上述修改,不要 ...

  9. IIS7.0/8.0的错误HTTP Error 500.19 - Internal Server Error ,错误代码为0x80070021

    最近在部署项目的时候,总是出现了这个问题. 大概原因为IIS7.0的安全设定相比前版本有很大的变更.IIS7.0的安全设置文件在%windir%\system32\inetsrv \config\ap ...

  10. spring事务(Transaction )报 marked as rollback-only异常的原因及解决方法

    很多朋友在使用spring+hibernate或mybatis等框架时经常遇到报Transaction rolled back because it has been marked as rollba ...