Skip to content

Instantly share code, notes, and snippets.

@mastersobg
Created October 6, 2013 14:29
Show Gist options
  • Select an option

  • Save mastersobg/6854759 to your computer and use it in GitHub Desktop.

Select an option

Save mastersobg/6854759 to your computer and use it in GitHub Desktop.
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