# Help me in solving ZCO14004 problem

### My code

``````#include <iostream>
#include<bits/stdc++.h>

using namespace std;
int solve(int *arr,int ind,int n,int inc,int dp[][2]){

if(ind>=n)return 0;
if(inc<2){
if(dp[ind][1]!=-1){
return dp[ind][1];
}
}
else{
if(dp[ind][0]!=-1)
return dp[ind][0];
}

int donot =dp[ind][0]= solve(arr,ind+1,n,0,dp);
int doselect = 0;
if(inc<2){
doselect =dp[ind][1]= arr[ind]+solve(arr,ind+1,n,inc+1,dp);
}
return max(donot,doselect);

}
int main() {
int n;
cin>>n;
int arr[n];
int dp[n+1][2]={-1};
for(int i=0;i<n;i++){
cin>>arr[i];
}
cout<<solve(arr,0,n,0,dp)<<endl;

return 0;
}

``````

Problem Link: CodeChef: Practical coding for everyone

@dhiru909
U have done wrong recursion
this is my code hope it helps.

``````#include <bits/stdc++.h>
using namespace std;
int cal(vector<int>& a,int i,int pre,vector<vector<int>>& dp)
{
// cout<<a.size()<<"y"<<endl;
if(i==a.size())
return 0;
if(dp[i][pre]!=-1)
{
return dp[i][pre];
}
if(pre==2)
{
return dp[i][pre]=cal(a,i+1,0,dp);
}
else
{
return dp[i][pre]=max(a[i]+cal(a,i+1,pre+1,dp),cal(a,i+1,0,dp));
}
}
int main() {