poj 4001 To Miss Our Children Time
Posted ZefengYao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj 4001 To Miss Our Children Time相关的知识,希望对你有一定的参考价值。
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?
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.
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 = 1000 + 5; 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 == 0)return b.l >= a.l&&b.w >= a.w; if (b.id == 1)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 = 0; i < n;i++) { dp[i] = cube[i].h; } for (int i = 1; i < n;i++) {//每次cube[i]要堆在最上面 for (int j = 0; 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 = 0; 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 0; }
以上是关于poj 4001 To Miss Our Children Time的主要内容,如果未能解决你的问题,请参考以下文章
SpringUnable to start ServletWebServerApplicationContext due to miss ServletWebServerFactory bean(代码
[Cycle.js] Hyperscript as our alternative to template languages
Our ultimate guide to Tianjin (in a day trip)
__twice,the postman refused to deliver our letters unless we chained our dog up.