Could You Please point out the mistake in my code I don’t want to go with the hint video I want to know whats wrong with my apporach
I am Unable to get the with my dp solution
The thing with your solution is that dp[i][j] makes no sense.
dp[a][b] should be no state.
Instead try to code a solution where dp[i][j] means that you have looked at i boxes and j of them have been taken by a.
Something like this
int dp[MAXN][MAXN];
int rec(int i, int cnt_a)
{
int cnt_b = i - cnt_a;
if(i == n) return 0;
int &memo = dp[i][cnt_a];
if(memo != -1) return memo;
memo = 0;
if(cnt_a < a) chkmax(memo, A[i] + rec(i + 1, cnt_a + 1));
if(cnt_b < b) chkmax(memo, B[i] + rec(i + 1, cnt_a));
return memo;
}