• 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 }
  • 相关阅读:
    C#获取视频文件播放长度
    ViewState跨页传值
    radio点击事件
    js屏蔽鼠标右键
    js获取url参数
    js页面跳转
    android 界面刷新功能
    android RadioButton单选按钮效果
    android TextView实现跑马灯效果(字体滚动)
    android 圆角效果
  • 原文地址:https://www.cnblogs.com/wangyiming/p/7259260.html
Copyright © 2020-2023  润新知