Please debug this i am getting wrong ans

#include<bits/stdc++.h>
using namespace std;

int max_points(int *a , int *b, int *c , int n, int *dp, int cur_act){
//base case
if(n==0){
return 0;
}
//look up
if(dp[n]!=-1){
return dp[n];
}
int op1 = INT_MIN;
int op2 = INT_MIN;
int op3 = INT_MIN;
if(cur_act!=1){
op1 = max_points(a,b,c,n-1,dp,1) + a[n];
//cout<<op1<<endl;
}
if(cur_act!=2){
op2 = max_points(a,b,c,n-1,dp,2) + b[n];
//cout<<op2<<endl;
}
if(cur_act!=3){
op3 = max_points(a,b,c,n-1,dp,3) + c[n];
//cout<<op3<<endl;
}
return dp[n] = max(op1, max(op2,op3));
}

int main(){
int n; cin>>n;
int a[n],b[n],c[n];
a[0]=b[0]=c[0] = 0;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i]>>c[i];
}
int dp[n+1];
for(int i=0;i<=n;i++){
dp[i]=-1;
}
/for(int i=1;i<=n;i++){
cout<<a[i]<<" “<<b[i]<<” "<<c[i]<<endl;
}
/
cout<<max_points(a,b,c,n,dp,0);
return 0;
}

hello @meetpa9

pls save ur code here->


and share its link with me

my logic of cur_act to determine the previous activity done isn’t working.






Also i’d be very thankful if you can reduce the redundancy further is possible

ur dp state is wrong.
u need to consider previous picked activity as well in ur dp state.
i.e
ur dp array should lool like -> dp[n][prev]

got that but how is this problem having overlapping subproblems?

(picked first , n-1) -> (picked third ,n-2) -> remining problem

(picked second ,n-1) -> (picked third, n-2) -> remaiing problem

see the state are repeating

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.