本文主要是介绍The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest To Miss Our Children Time,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://acm.hdu.edu.cn/showproblem.php?pid=4001
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
思路:这一题属于dp题,难点我认为就是排序的问题,总是把条件苛刻的放在最下面。。。。。
代码:
#include<iostream>
#include<algorithm>
using namespace std;
struct block{ long long a,b,c,d;}aa[1005];
bool cmp(block x,block y)
{ if(x.a!=y.a) return x.a<y.a;//按长从小到大排序。if(x.b!=y.b) return x.b<y.b;//按宽从小到大排序。return x.d>y.d;//按编号从大到小排序
}
long long dp[1005];
int main()
{ int n;while(cin>>n,n){ for(int i=0;i<n;i++){ cin>>aa[i].a>>aa[i].b>>aa[i].c>>aa[i].d;if(aa[i].a<aa[i].b) swap(aa[i].a,aa[i].b);dp[i]=0;} sort(aa,aa+n,cmp);long long ans=0;for(int i=0;i<n;++i){ dp[i]=aa[i].c;for(int j=0;j<i;++j)//每次都把当前的block和它前面的比较从而确定把该block放在最上面时的最大厚度。{ if(aa[i].d==0&&aa[i].a>=aa[j].a&&aa[i].b>=aa[j].b)dp[i]=max(dp[i],dp[j]+aa[i].c);if(aa[i].d==1&&aa[i].a>=aa[j].a&&aa[i].b>=aa[j].b&&(aa[i].a>aa[j].a||aa[i].b>aa[j].b))dp[i]=max(dp[i],dp[j]+aa[i].c);if(aa[i].d==2&&aa[i].a>aa[j].a&&aa[i].b>aa[j].b)dp[i]=max(dp[i],dp[j]+aa[i].c);}if(dp[i]>ans) ans=dp[i];//把每次求出的最大厚度和最大厚度相比从而求出最大厚度。}cout<<ans<<endl;
}return 0;}
这篇关于The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest To Miss Our Children Time的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!