https://blog.csdn.net/libin56842/article/details/9338841
HDU2602:Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602
经典的01背包题,给出了石头的数量与背包的容量,然后分别给出每个石头的容量与价值,要求最优解,经过前面的练手,这道题已经是很简单了,可以说是01背包果题。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct Node
{
int h;
int v;
} node[1005];
int main()
{
int t,n,m,l;
int dp[1005];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
int i;
for(i = 1; i<=n; i++)
scanf("%d",&node[i].h);
for(i = 1; i<=n; i++)
scanf("%d",&node[i].v);
memset(dp,0,sizeof(dp));
for(i = 1; i<=n; i++)
{
for(l = m; l>=node[i].v; l--)
dp[l] = max(dp[l],dp[l-node[i].v]+node[i].h);
}
printf("%d\n",dp[m]);
}
return 0;
}