首页 > 代码库 > poj 4001 To Miss Our Children Time
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。