Guest User

ZCO IPL

a guest
Nov 14th, 2015
215
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. #include <algorithm>
  4.  
  5. int func(int li[], int n = 0, int a = 0, int b = 0)
  6. {
  7.     if (a >= n)
  8.         return 0;
  9.    
  10.     if (b == 0)
  11.         return 0;
  12.    
  13.     return max(max(func(li, n, a+1, b-1) + li[a], func(li, n, a+2, b) + li[a]), func(li, n, a+1, b));
  14. }
  15.  
  16. int main()
  17. {
  18.     int n;
  19.     cin >> n;
  20.     int li[n];
  21.    
  22.     for (int i = 0; i < n; i++)
  23.         cin >> li[i];
  24.      
  25.     int revenue = 0;
  26.    
  27.     revenue = func(li, n, 0, 2);
  28.    
  29.     cout << revenue;
  30.     return 0;
  31. }
RAW Paste Data