比赛 |
202103省实验桐柏一中普及组联赛 |
评测结果 |
AWAWWAWWAW |
题目名称 |
自助者天助 |
最终得分 |
40 |
用户昵称 |
fsdh |
运行时间 |
0.126 s |
代码语言 |
C++ |
内存使用 |
2.24 MiB |
提交时间 |
2021-03-22 20:16:25 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e4 + 5;
int n, m, W[MAXN], V[MAXN], s[MAXN], cnt = 0, dp[MAXN];
bool f;
int main () {
memset (s, 0, sizeof (s));
freopen ("delicious.in", "r", stdin);
freopen ("delicious.out", "w", stdout);
scanf ("%d%d", &n, &m);
for (int q = 1, x, y; q <= n; ++q) {
f = false;
scanf ("%d%d", &x, &y);
for (int w = 1; w <= cnt; ++w) {
if (W[w] == x && V[w] == y) {
s[w] ++;
f = true;
}
}
if (!f) {
W[++cnt] = x, V[cnt] = y;
s[cnt] = 1;
}
}
for (int q = 1; q <= cnt; ++q) {
int b = 1;
while (s[q]) {
if (s[q] & 1) {
int WW = b * W[q], VV = b * V[q];
for (int w = m; w >= WW; --w) {
dp[w] = max (dp[w], dp[w - WW] + VV);
}
}
s[q] >>= 1;
b <<= 1;
}
}
printf ("%d\n", dp[m]);
return 0;
}