QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#464316 | #6955. Assignment | fractal | WA | 311ms | 184836kb | C++14 | 1.9kb | 2024-07-06 00:44:07 | 2024-07-06 00:44:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, a[121], b[121], k;
int dp[121][121][121][31];
int C[121][121], f[121][121][31];
void solve() {
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
cin >> b[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> C[i][j];
}
}
const int inf = 1e9 + 100;
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
for (int x = 0; x <= n; ++x) {
for (int l = 0; l <= k; ++l) {
f[i][j][l] = inf;
dp[i][j][x][l] = inf;
}
}
}
}
for (int i = 1; i <= n; ++i) {
for (int x = 1; x <= n; ++x) {
dp[i][i][x][x != b[i]] = 0;
f[i][i][x != b[i]] = min(f[i][i][x != b[i]], C[x][1]);
}
dp[i][i][0][a[i] != b[i]] = 0;
f[i][i][a[i] != b[i]] = 0;
}
for (int len = 2; len <= n; ++len) {
for (int l = 1, r = len; r <= n; ++l, ++r) {
for (int x = 1; x <= n; ++x) {
for (int j = 0; j <= k; ++j) {
int jj = jj = j + (x!=b[l]) + (x != b[r]);
if (jj <= k) dp[l][r][x][jj] = min(dp[l][r][x][jj], dp[l + 1][r - 1][x][j]);
}
for (int j = 0; j <= k; ++j) {
f[l][r][j] = min(f[l][r][j], C[x][len] + dp[l][r][x][j]);
}
}
for (int i = l; i < r; ++i) {
for (int x = 0; x <= k; ++x) {
for (int y = 0; x + y <= k; ++y) {
dp[l][r][0][x + y] = min(dp[l][r][0][x + y], f[l][i][x] + f[i + 1][r][y]);
f[l][r][x + y] = min(f[l][r][x + y], dp[l][r][0][x + y]);
}
}
}
}
}
//~ n = 3;
//~ cout << dp[2][4][2][0] << '\n';
//~ cout << f[1][4][0] << '\n';
int ans = f[1][n][0];
cout << ans << " ";
for (int i = 1; i <= k; ++i) {
ans = min(ans, f[1][n][i]);
cout << ans << " \n"[i == k];
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 311ms
memory: 184836kb
input:
10 100 10 24 56 71 49 70 39 19 23 96 26 85 33 73 84 35 75 58 77 85 40 33 36 75 55 7 28 37 7 100 94 35 64 68 46 77 80 90 28 85 8 9 23 32 45 4 51 47 82 6 49 45 55 28 69 80 7 61 41 83 42 16 25 82 56 26 92 14 66 43 1 2 62 25 84 19 58 35 37 14 61 38 12 27 95 98 100 61 36 75 83 35 19 74 56 87 10 10 6 60 5...
output:
31600238 30666836 29442902 28509500 27611633 26713766 25824070 24975790 24187816 23411362 22638520 37783284 36797918 35872445 35000395 34153780 33307165 32506273 31705381 30904489 30122479 29378306 6013780 4910683 4154163 3524317 3086984 2846866 2707053 2630337 2545481 2308065 2067947 8450199 715125...
result:
wrong answer 1st lines differ - expected: '27473279 26539877 25650181 248...3001 20960159 20221324 19493165', found: '31600238 30666836 29442902 285...5790 24187816 23411362 22638520'