Advertisement
Josif_tepe

Untitled

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