|
|
back to boardgenerate all sums with recursion #include <iostream> #include <stdio.h> #include <memory.h> #define NMAX 37 using namespace std; long cnt[NMAX]; int n; void genSum(int k, int sum); int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); ///freopen("output.txt", "wt", stdout); #endif scanf("%d", &n); genSum (0 , 0); int answer = 0; for (int it = 9 * n / 2; it >= 0; --it) { answer += cnt[it] * cnt[it]; } printf("%d\n", answer); return 0; } void genSum(int k, int sum) { if (k == n / 2) { ++cnt[ sum ]; } else for (int digit = 0; digit <= 9; ++digit) { genSum(k + 1, sum + digit); } } |
|
|