Description
Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.
Input
* Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.
Output
Sample Input
3
7 40 3
5 23 8
2 52 6
Sample Output
48
Hint
From the bottom: 3 blocks of type 2, below 3 of type 1, below 6 of type 3. Stacking 4 blocks of type 2 and 3 of type 1 is not legal, since the top of the last type 1 block would exceed height 40.
<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int dp[40005],sum[40005];
int n;
struct node{
int h,a,c;
bool operator <(const node &x)const{
return a<x.a;
}
}nod[405];
int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%d %d %d",&nod[i].h,&nod[i].a,&nod[i].c);
sort(nod,nod+n);
memset(dp,0,sizeof(dp));
dp[0]=1;
int ans=0;
for(int i=0;i<n;i++){
memset(sum,0,sizeof(sum));
for(int j=nod[i].h;j<=nod[i].a;j++){
if(!dp[j] && dp[j-nod[i].h] && sum[j-nod[i].h]<nod[i].c)
{
sum[j]=sum[j-nod[i].h]+1;
dp[j]=1;
if(ans<j)
ans=j;
}
}
}
printf("%d\n",ans);
}
return 0;
}
</span>
2万+



被折叠的 条评论
为什么被折叠?



