This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 51, C = 1000, INF = 2e9;
int dp[C][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 < C; 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 < C; 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 && x + w[y][to] < C) {
dp[x + w[y][to]][to][z] = max(dp[x + w[y][to]][to][z],
dp[x][y][z]);
if (z != 0 && s[to][z] != -1) {
dp[x + w[y][to]][to][0] = max(dp[x + w[y][to]][to][0],
dp[x][y][z] + s[to][z]);
}
}
}
}
}
}
}
for (int x = 1; x < C; 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... |