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. 01_5_Struts_ActionMethod_DMI_动态方法调用

    01_5_Struts_ActionMethod_DMI_动态方法调用 1. ActionMethod_DMI_动态方法调用 Action执行的时候并不一定要执行execute()方法 可以在配置文件 ...

  2. 01_2_Namespace命名空间

    01_2_Namespace命名空间 1. Namespace_命名空间 namespace决定了action的访问路径,默认为””,可以接收所有路径的action namespace可以写为/,或者 ...

  3. Check for Palindromes-freecodecamp算法题目

    Check for Palindromes(检查回文字符串) 要求 给定的字符串是回文,返回true,反之,返回false.(如果一个字符串忽略标点符号.大小写和空格,正着读和反着读一模一样,那么这个 ...

  4. 字节跳动后端开发实习生面试(Python)

    一面: 1.自我介绍. 2.介绍“工大小美”项目相关. 3.Python中的GIL(全局解释器锁),以及哪种情况下使用python的多线程性能有较大的提升. 4.项目中用到了SQLite数据库,如果有 ...

  5. linux系统入门—文件管理

    目录 linux系统入门-文件管理 系统目录结构 目录管理 linux系统入门-文件管理 系统目录结构 几乎所有的计算机操作系统都是使用目录结构组织文件.具体来说就是在一个目录中存放子目录和文件,而在 ...

  6. 20181207(sys,shelve,logging)

    一.logging模块 logging专门用来记录日志 日志的级别分为五级,可以用数字表示,从低到高分别为: import  logginglogging.info('info')   #10logg ...

  7. python2和python3,字典和json

    Python2的标准数据类型有: Numbers (数字) String (字符串) List (列表) Tuple (元组) Dictionary (字典) Python3的标准数据类型有: Num ...

  8. win7 怎么进入注册表

    windows图标键(就是ALT旁边的windows小旗子)+R键----输入"regedit"---回车

  9. SMP IRQ Affinity

    转:非常有用的方法,调式神器 SMP IRQ Affinity Background: Whenever a piece of hardware, such as disk controller or ...

  10. Python属性描述符(一)

    描述符是对多个属性运用相同存取逻辑的一种方式,,是实现了特性协议的类,这个协议包括了__get__.__set__和__delete__方法.property类实现了完整的描述符协议.通常,可以只实现 ...