Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: david.h2
- LANG: C++11
- TASK: nocows
- */
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<vector<int>> results(201, vector<int>(101, -1));
- int findntrees(int n, int k) {
- if (n == 0){
- results[n][k] = 1;
- } else if (k == 0) {
- results[n][k] = 0;
- } else if (results[n][k] == -1) {
- int childpossibilities = 0;
- for (int leftnodes = 0; leftnodes <= n - 2; leftnodes+=2) {
- int rleft = findntrees(leftnodes, k - 1);
- int rright = findntrees(n - 2 - leftnodes, k - 1);
- childpossibilities += rleft * rright;
- childpossibilities %= 9901;
- }
- results[n][k] = childpossibilities % 9901;
- }
- return results[n][k] % 9901;
- }
- int main() {
- FILE *fin = fopen("nocows.in", "r");
- FILE *fout = fopen("nocows.out", "w");
- int n, k;
- fscanf(fin, "%d %d", &n, &k);
- if (n % 2 == 0) {
- fprintf(fout, "%d\n", 0);
- return 0;
- }
- n -= 1;
- k -= 1;
- fprintf(fout, "%d\n", ((findntrees(n, k) + 9901) - findntrees(n, k - 1)) % 9901);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement