Created
June 4, 2021 11:27
-
-
Save nachiketkanore/b852b16cf15b4e26fc771a0baa37a3a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int dp[MAXN][MAXN]; // assign all to -1 | |
int go(int id, int have){ | |
if(have < 0) | |
return -inf; | |
if(id > n) | |
return 0; | |
int &ans = dp[id][have]; | |
if(ans != -1) | |
return ans; | |
ans = 0; | |
int take = 1 + go(id+1, have - c[id]); | |
int dont_take = go(id + 1, have); | |
ans = max({ans, take, dont_take}); | |
return ans; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment