Advertisement
Josif_tepe

Untitled

Oct 24th, 2021
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. typedef long long ll;
  5. int arr[100005][3];
  6. ll dp[51][51][51];
  7. ll kolacinja(int W, int B, int R, int i) {
  8.     if(i == -1) {
  9.         return 0;
  10.     }
  11.     if(dp[W][B][R] != -1) {
  12.         return dp[W][B][R];
  13.     }
  14.     ll result = 0;
  15.     if(W > 0) {
  16.         result = max(result, kolacinja(W - 1, B, R, i - 1) + arr[i][0]);
  17.     }
  18.     if(B > 0) {
  19.         result = max(result, kolacinja(W, B - 1, R, i - 1) + arr[i][1]);
  20.     }
  21.     if(R > 0) {
  22.         result = max(result, kolacinja(W, B, R - 1, i - 1) + arr[i][2]);
  23.     }
  24.     return dp[W][B][R] = result;
  25. }
  26. int main()
  27. {
  28.     int w, b, r, n;
  29.     cin >> w >> b >> r >> n;
  30.     for(int i = 0; i < n; i++) {
  31.         cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
  32.     }
  33.     for(int i = 0; i < 51; i++) {
  34.         for(int j = 0; j < 51; j++) {
  35.             for(int k = 0; k < 51; k++) {
  36.                 dp[i][j][k] = -1;
  37.             }
  38.         }
  39.     }
  40.     if(n <= 50) {
  41.         cout << kolacinja(w, b, r, n - 1) << endl;
  42.     }
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement