Created
June 4, 2021 11:19
-
-
Save nachiketkanore/ea9eb778e66568b1781a720e5404d74d to your computer and use it in GitHub Desktop.
Dynamic Programming
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 go(int id, int have){ | |
if(have < 0) | |
return -inf; | |
if(id > n) | |
return 0; | |
int ans = -inf; | |
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