毫不夸张的说:USACO里2.3节最难的动规、、、
基本是照着题解一个字一个字对的。。。。
题号:1472
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<cstdlib> #include<cstring> #include<iostream> #include<string> #include<vector> #include<algorithm> #define MOD 9901 using namespace std; int n, k; long long f[210][110],dp[210][110]; //必须是long long int main(){ cin >> n >> k; //if (n % 2 == 0){ // cout << 0 << endl; // return 0; //} dp[1][1] = 1; f[0][0] = 1; for (int i = 1; i <= k; i++)f[1][i] = f[0][i] = 1; for (int i = 3; i <= n; i += 2){ //i:Node Num;j:depth int j = 1; while ((1 << j) - 1 < i)j++; for (; j <= k; j++){ for (int l = 1; l <= i - 1; l += 2){ dp[i][j] += dp[l][j - 1] * f[i - l - 1][j - 2]; dp[i][j] += f[l][j - 2] * dp[i - l - 1][j - 1]; dp[i][j] += dp[l][j - 1] * dp[i - l - 1][j - 1]; } dp[i][j] %= MOD; } for (int j = 1; j <= k; j++)f[i][j] = (f[i][j - 1] + dp[i][j]) % MOD; } cout << dp[n][k] << endl; } |