제출 #161837

#제출 시각아이디문제언어결과실행 시간메모리
161837Minnakhmetov여행하는 상인 (APIO17_merchant)C++14
0 / 100
32 ms2808 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...