QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625108 | #5301. Modulo Ruins the Legend | adivse# | WA | 1ms | 7768kb | C++20 | 1.9kb | 2024-10-09 17:28:48 | 2024-10-09 17:28:48 |
Judging History
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