题目链接:(—_—) zZ
题目大意:The cows are going to space(吐槽:牛要上太空?这真的牛逼),现在奶牛要搭建一个上太空的电梯, 用的是高科技材料板砖,每个板砖有一定的高度,和它最高能堆积在a_i高度处,现在给出k个板砖的信息(每个砖的高度, 所能在的最大高度, 和个数), 求能堆积出的电梯最大高度.
思路:多重背包问题, 把板砖的所在最大高度看成容量, 从小到大的动态转移.
题目大意:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define max(a,b) a>b? a:b
struct node
{
int h, a, c;
}type[405];
int dp[40002], num[40002];
int cmp(void const *a, void const *b)
{
return (*(struct node *)a).a-(*(struct node *)b).a;
}
int main()
{
int i = 0, j = 0, k = 0, m = 0;
while(scanf("%d", &k) != EOF)
{
m = 0;
for(i = 0; i<k; i++)
{
scanf("%d %d %d", &type[i].h, &type[i].a, &type[i].c);
if(m<type[i].a)
m = type[i].a;
}
qsort(type, k, sizeof(type[0]), cmp);
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for(i = 0; i<k; i++)
{
memset(num, 0, sizeof(num));
for(j = type[i].h; j<=type[i].a; j++)
{
if(!dp[j] && dp[j-type[i].h] && num[j-type[i].h]<type[i].c)
{
dp[j] = 1;
num[j] = num[j-type[i].h]+1;
}
}
}
for(i = m; i>=0; i--)
if(dp[i])
{
printf("%d\n", i);
break;
}
}
return 0;
}