CF414B Mashmokh and ACM
Posted 王宜鸣
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF414B Mashmokh and ACM相关的知识,希望对你有一定的参考价值。
思路:
dp。
实现:
1.O(n5/2)
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 const int MOD = 1e9 + 7; 6 7 int n, k, dp[2005][2005]; 8 9 int solve() 10 { 11 for (int i = 1; i <= n; i++) dp[0][i] = 1; 12 for (int i = 1; i < k; i++) 13 { 14 for (int j = 1; j <= n; j++) 15 { 16 for (int p = 1; p * p <= j; p++) 17 { 18 if (j % p == 0) 19 { 20 dp[i][j] = (dp[i][j] + dp[i - 1][p]) % MOD; 21 if (p * p != j) dp[i][j] = (dp[i][j] + dp[i - 1][j / p]) % MOD; 22 } 23 } 24 } 25 } 26 int sum = 0; 27 for (int i = 1; i <= n; i++) sum = (sum + dp[k - 1][i]) % MOD; 28 return sum; 29 } 30 31 int main() 32 { 33 cin >> n >> k; 34 cout << solve() << endl; 35 return 0; 36 }
2.O(n2log(n))
1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 5 const int MOD = 1e9 + 7; 6 7 int n, k, dp[2005][2005]; 8 9 int solve() 10 { 11 for (int i = 1; i <= n; i++) dp[0][i] = 1; 12 for (int i = 1; i < k; i++) 13 { 14 for (int j = 1; j <= n; j++) 15 { 16 for (int p = j; p <= n; p += j) 17 { 18 dp[i][p] = (dp[i][p] + dp[i - 1][j]) % MOD; 19 } 20 } 21 } 22 int sum = 0; 23 for (int i = 1; i <= n; i++) sum = (sum + dp[k - 1][i]) % MOD; 24 return sum; 25 } 26 27 int main() 28 { 29 cin >> n >> k; 30 cout << solve() << endl; 31 return 0; 32 }
以上是关于CF414B Mashmokh and ACM的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces 415D Mashmokh and ACM
Mashmokh and ACM CodeForces - 414D (贪心)
[CF414E]Mashmokh's Designed Problem