Created
October 6, 2013 14:29
-
-
Save mastersobg/6854759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 rec(int n, int cnt) { | |
| if (cnt == 0) { | |
| return n == 0 ? 1 : 0; | |
| } | |
| int ret = dp[cnt][n]; | |
| if (ret == -1) { | |
| ret = 0; | |
| for (int p : primes) { | |
| if (p <= n) { | |
| ret += rec(n - p, cnt - 1); | |
| } else { | |
| break; | |
| } | |
| } | |
| dp[cnt][n] = ret; | |
| } | |
| return ret; | |
| } | |
| main() { | |
| ... | |
| int ret = rec(n, 4); | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment