# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
759284 | boyliguanhan | Travelling Merchant (APIO17_merchant) | C++17 | 0 ms | 0 KiB |
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>
using namespace std;
int calc[10][100][1000], b[10][100], s[10][100], N, k, m;
vector<pair<int, int>> adj[5];
void dfs(int n, int item, int dist, int profit) {
if(calc[n][item][dist]>=profit) continue;
calc[n][item][dist] = profit;
if(item) {
if(s[n][item]>0)
dfs(n, 0, dist, profit+s[n][item]);
} else {
for(int i = 1; i <= k; i++)
dfs(n,i,dist,profit-b[n][i]);
}
for(auto i: adj[n]) {
dfs(i.first, item, dist+i.second, profit);
}
}
int main() {
memset(calc, -2, sizeof calc);
cin >> N >> k >> m;
for(int i = 0; i < N; i++) {
for(int j = 1; j <= k; j++)
cin >> b[i][j];
for(int j = 1; j <= k; j++)
cin >> s[i][j];
}
while(m--) {
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({b, c});
}
dfs(0,0,0,0);
int ans = 0;
for(int i = 1; i < 100; i++) {
ans = max(ans, calc[0][0][i]/i);
}
cout << ans << '\n';
}