QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625096#5303. No Bug No Gameadivse#WA 71ms145020kbC++201.9kb2024-10-09 17:26:412024-10-09 17:26:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 17:26:43]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:145020kb
  • [2024-10-09 17:26:41]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 3005;
const int inf = 1e9;

int n, k, p[N];
vector<int>w[N];

int dp[2][3005][3005];

void out(int x) {
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= k; ++j) {
            cout << dp[x][i][j] << ' ';
        }
        cout << endl;
    }
    cout << endl;
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> p[i];
        w[i].push_back(0);
        for (int j = 0; j < p[i]; ++j) {
            int x; cin >> x;
            w[i].push_back(x);
        }
    }

    for (int i = 0; i <= n + 1; ++i)
        for (int j = 0; j <= k; ++j)
            dp[0][i][j] = dp[1][i][j] = -inf;
    dp[0][0][0] = dp[1][n + 1][0] = 0;

    for (int i = 1; i <= n; ++i) {
        dp[0][i][0] = 0;
        for (int j = k; j >= p[i]; --j) {
            dp[0][i][j] = max(dp[0][i][j], dp[0][i - 1][j - p[i]] + w[i][p[i]]);
            dp[0][i][j] = max(dp[0][i][j], dp[0][i - 1][j]);
        }
    }

    for (int i = n; i >= 1; --i) {
        dp[1][i][0] = 0;
        for (int j = k; j >= p[i]; --j) {
            dp[1][i][j] = max(dp[1][i][j], dp[1][i + 1][j - p[i]] + w[i][p[i]]);
            dp[1][i][j] = max(dp[1][i][j], dp[1][i + 1][j]);
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {//i the chosen item  -----------i
        for (int j = 1; j <= p[i]; ++j) {//j the chosen weight  --j
            for (int o = 0; o <= k - j; ++o) {//weight front  ----o
                //cout << ans << ' ' << w[i][j] << ' ' << dp[0][i - 1][o] << ' ' << ' ' << dp[1][i + 1][k - j - o] << endl;
                ans = max(ans, w[i][j] + dp[0][i - 1][o] + dp[1][i + 1][k - j - o]);
            }
        }
    }
    //out(0); out(1);
    cout << ans;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5664kb

input:

4 5
2 1 3
2 1 1
2 3 1
2 1 3

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: -100
Wrong Answer
time: 71ms
memory: 145020kb

input:

3000 3000
10 70562 30723 79371 82224 63977 3362 26909 96449 48163 66159
4 18007 33590 80674 91139
4 10304 31694 70745 50656
10 63090 17226 13187 73881 38137 15237 55750 82751 75854 39658
8 95640 66120 87735 36388 44046 92415 6952 94772
9 60565 27904 98726 87052 35768 25453 14563 34273 92501
10 66332...

output:

68231163

result:

wrong answer 1st numbers differ - expected: '68279788', found: '68231163'