QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625108#5301. Modulo Ruins the Legendadivse#WA 1ms7768kbC++201.9kb2024-10-09 17:28:482024-10-09 17:28:48

Judging History

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

  • [2024-10-09 17:28:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7768kb
  • [2024-10-09 17:28:48]
  • 提交

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 >= 0; --j) {
            if (j - p[i] >= 0)
                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 >= 0; --j) {
            if (j - p[i] >= 0)
                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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7768kb

input:

6 24
1 1 4 5 1 4

output:

0

result:

wrong output format Unexpected end of file - int32 expected