记录编号 559842 评测结果 AWAWWAWWAW
题目名称 自助者天助 最终得分 40
用户昵称 Gravataryrtiop 是否通过 未通过
代码语言 C++ 运行时间 0.116 s
提交时间 2021-03-24 20:34:28 内存使用 2.24 MiB
显示代码纯文本
#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;
}