1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 55; 4 int dp1[maxn][maxn], dp2[maxn][maxn], dp3[maxn][maxn], dp4[maxn][maxn]; 5 void init() { 6 for (int n = 1; n <= 50; n++) { 7 for (int k = 1; k <= 50; k++) { 8 if (n == k) dp1[n][k] = 1; 9 else if (n < k) dp1[n][k] = 0; 10 else dp1[n][k] = dp1[n-k][k]+dp1[n-1][k-1]; 11 } 12 } 13 14 for (int n = 1; n <= 50; n++) { 15 dp2[n][1] = n==1 ? 1 : 0; 16 for (int m = 2; m <= 50; m++) { 17 if (n < m) dp2[n][m] = dp2[n][n]; 18 else if (n == m) dp2[n][m] = dp2[n][m-1]+1; 19 else dp2[n][m] = dp2[n][m-1]+dp2[n-m][m-1]; 20 } 21 } 22 23 for (int n = 1; n <= 50; n++) { 24 dp3[n][1] = (n%2), dp4[n][1] = (n%2==0); 25 dp3[n][0] = dp3[n][1]; 26 for (int m = 2; m <= 50; m++) { 27 if (n < m) dp3[n][m] = dp4[n][m] = 0; 28 else if (n == m) dp3[n][m] = 1, dp4[n][m] = 0; 29 else { 30 dp3[n][m] = dp3[n-1][m-1]+dp4[n-m][m]; 31 dp4[n][m] = dp3[n-m][m]; 32 } 33 dp3[n][0] += dp3[n][m]; 34 } 35 } 36 } 37 int main() { 38 init(); 39 int n, k; 40 while (cin >> n >> k) { 41 cout << dp1[n][k] << endl; 42 cout << dp2[n][n] << endl; 43 cout << dp3[n][0] << endl; 44 } 45 return 0; 46 }
原文地址:https://www.cnblogs.com/wstong/p/11749362.html
时间: 2024-10-27 18:03:41