Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m, C;
- int dp[10][10], was[10][10];
- int cnt[10][10], r[10];
- int go (int cars, int routes) {
- if (was[cars][routes]) return dp[cars][routes];
- if (cars < routes || (cars != 0 && !routes)) return -1;
- was[cars][routes] = 1;
- dp[cars][routes] = -1;
- for (int cur = 1; cur <= cars - routes + 1; cur++) {
- int last = dp[cars - cur][routes - 1];
- if (last != -1) {
- dp[cars][routes] = max (dp[cars][routes], last + cnt[routes][cur] * C - r[routes] * cur);
- }
- }
- return dp[cars][routes];
- }
- int main() {
- cin >> n >> m >> C;
- for (int i = 1; i <= n; i++) cin >> r[i];
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= m; j++)
- cin >> cnt[i][j];
- was[0][0] = 1;
- cout << go (m, n) << endl;
- }
- /*
- 3 5
- 30
- 3000 2500 2000
- 300 500 600 600
- 300 600 700 700
- 300 450 500 500
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement