Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int arr[100005][3];
- ll dp[51][51][51];
- ll kolacinja(int W, int B, int R, int i) {
- if(i == -1) {
- return 0;
- }
- if(dp[W][B][R] != -1) {
- return dp[W][B][R];
- }
- ll result = 0;
- if(W > 0) {
- result = max(result, kolacinja(W - 1, B, R, i - 1) + arr[i][0]);
- }
- if(B > 0) {
- result = max(result, kolacinja(W, B - 1, R, i - 1) + arr[i][1]);
- }
- if(R > 0) {
- result = max(result, kolacinja(W, B, R - 1, i - 1) + arr[i][2]);
- }
- return dp[W][B][R] = result;
- }
- int main()
- {
- int w, b, r, n;
- cin >> w >> b >> r >> n;
- for(int i = 0; i < n; i++) {
- cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
- }
- for(int i = 0; i < 51; i++) {
- for(int j = 0; j < 51; j++) {
- for(int k = 0; k < 51; k++) {
- dp[i][j][k] = -1;
- }
- }
- }
- if(n <= 50) {
- cout << kolacinja(w, b, r, n - 1) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement