Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, m, C;
  6.  
  7. int dp[10][10], was[10][10];
  8. int cnt[10][10], r[10];
  9.  
  10.  
  11. int go (int cars, int routes) {
  12. if (was[cars][routes]) return dp[cars][routes];
  13. if (cars < routes || (cars != 0 && !routes)) return -1;
  14.  
  15. was[cars][routes] = 1;
  16. dp[cars][routes] = -1;
  17. for (int cur = 1; cur <= cars - routes + 1; cur++) {
  18. int last = dp[cars - cur][routes - 1];
  19. if (last != -1) {
  20. dp[cars][routes] = max (dp[cars][routes], last + cnt[routes][cur] * C - r[routes] * cur);
  21. }
  22. }
  23. return dp[cars][routes];
  24. }
  25.  
  26. int main() {
  27.  
  28. cin >> n >> m >> C;
  29. for (int i = 1; i <= n; i++) cin >> r[i];
  30.  
  31. for (int i = 1; i <= n; i++)
  32. for (int j = 1; j <= m; j++)
  33. cin >> cnt[i][j];
  34.  
  35. was[0][0] = 1;
  36. cout << go (m, n) << endl;
  37. }
  38.  
  39. /*
  40. 3 5
  41. 30
  42. 3000 2500 2000
  43.  
  44. 300 500 600 600
  45. 300 600 700 700
  46. 300 450 500 500
  47. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement