#include<stdio.h>
int max(int a, int b)
{
return (a > b ? a : b);
}
struct E
{
int W;
int price;
}list[1001];
int dp[1001];
int main()
{
int s, n;
while (scanf("%d%d", &s, &n) != EOF)
{
int cnt = 0;
for (int i = 1; i <= n; i++)
{
int w, p, num;
scanf("%d%d%d", &w, &p, &num);
int c = 1;
while (num - c > 0)
{
list[++cnt].W = w * c;
list[cnt].price = p * c;
c *= 2;
}
list[++cnt].W = num * w;
list[cnt].price = p * num;
}
for (int i = 1; i <= s; i++)
dp[i] = 0;
for (int i = 1; i <= cnt; i++)
for (int j = s; j >= list[i].W; j--)
dp[j] = max(dp[j], dp[j - list[i].W] + list[i].price);
printf("%d\n", dp[s]);
}
return 0;
}
多重背包问题
最新推荐文章于 2022-03-07 18:28:16 发布