이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 51, INF = 2e9;
int dp[N][N][N], b[N][N], s[N][N], w[N][N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
w[i][j] = INF;
}
}
for (int i = 0; i < n; i++) {
for (int j = 1; j <= k; j++) {
cin >> b[i][j] >> s[i][j];
}
}
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
w[a][b] = min(w[a][b], c);
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int x = 0; x <= n; x++) {
for (int y = 0; y < n; y++) {
for (int z = 0; z <= k; z++) {
dp[x][y][z] = -INF;
}
}
}
dp[0][i][0] = 0;
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
if (dp[x][y][0] != -INF) {
for (int z = 1; z <= k; z++) {
if (b[y][z] != -1) {
dp[x][y][z] = max(dp[x][y][z],
dp[x][y][0] - b[y][z]);
}
}
}
for (int z = 0; z <= k; z++) {
if (dp[x][y][z] != -INF) {
for (int to = 0; to < n; to++) {
if (w[y][to] != INF) {
dp[x + 1][to][z] = max(dp[x + 1][to][z],
dp[x][y][z]);
if (z != 0 && s[to][z] != -1) {
dp[x + 1][to][0] = max(dp[x + 1][to][0],
dp[x][y][z] + s[to][z]);
}
}
}
}
}
}
}
for (int x = 1; x <= n; x++) {
cout << x << " " << i << " " << dp[x][i][0] << "\n";
ans = max(ans, dp[x][i][0] / x);
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |