rt,时限卡的太紧了。
#include <iostream>
const int maxn = 40050;
int n,m,dp[maxn],c[maxn],v[105],w[105],l[105];
int main(){
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++) scanf("%d%d%d",&w[i],&v[i],&l[i]);
for (int i = 1; i <= n; i++) {
int tot = 0,x = 1;
while (l[i]) {
if (x <= l[i]) c[++tot] = x,l[i] -= x;
else c[++tot] = l[i],l[i] = 0;
}
for (int j = 1; j <= tot; j++)
for (int k = m; k >= v[i] * c[j]; k--)
dp[k] = std::max(dp[k],dp[k - v[i] * c[j]] + w[i]);
}
printf("%d",dp[m]);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int maxn = 40050;
int n,m,dp[maxn],c[maxn];
struct node {
int v,w,l;
} a[maxn];
int main(){
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; i++) scanf("%d%d%d",&a[i].w,&a[i].v,&a[i].l);
for (int i = 1; i <= n; i++) {
int tot = 0,x = 1;
while (a[i].l) {
if (x <= a[i].l) c[++tot] = x,a[i].l -= x;
else c[++tot] = a[i].l,a[i].l = 0;
}
for (int j = 1; j <= tot; j++)
for (int k = m; k >= a[i].v * c[j]; k--)
dp[k] = max(dp[k],dp[k - a[i].v * c[j]] + a[i].w);
}
printf("%d",dp[m]);
return 0;
}
望管理改正!
@Maxmilite