【背包】SSL_1317 灵魂分流药剂
作者:互联网
题意
二维费用的分组背包。
思路
套模板即可。
代码
#include<cstdio>
#include<algorithm>
struct node{
int w, v, t, p;
}c[111];
int s[15], tt[15], f[15][111][111];
int n, m, a, b, ans;
int cmp(node x, node y) {
return x.t < y.t;
}
int main() {
scanf("%d %d %d %d", &n, &m, &a, &b);
for (int i = 1; i <= n; i++)
scanf("%d %d %d %d", &c[i].w, &c[i].v, &c[i].t, &c[i].p);
std::sort(c + 1, c + n + 1, cmp);
for (int i = 1; i <= n; i++)
if (c[i].t != c[i - 1].t) s[c[i].t] = i;
s[m + 1] = n + 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= a; j++)
for (int k = 0; k <= b; k++)
f[i][j][k] = f[i - 1][j][k];
for (int xx = s[i]; xx < s[i + 1]; xx++)
for (int j = a; j >= c[xx].w; j--)
for (int k = b; k >= c[xx].v; k--)
f[i][j][k] = std::max(f[i][j][k], f[i - 1][j - c[xx].w][k - c[xx].v] + c[xx].p);
}
printf("%d", f[m][a][b]);
}
标签:1317,node,15,int,药剂,SSL,xx,111,include 来源: https://blog.csdn.net/SSL_hzb/article/details/89601063