zoukankan      html  css  js  c++  java
  • CF 414B Mashmokh and ACM 动态规划

    题意:

      给你两个数n和k。求满足以下条件的数列有多少个。

      这个数列的长度是k: b[1], b[2], ……, b[k]。 并且 b[1] <= b[2] <= …… <= b[k] <= n;

      而且,前一个数能被后一个数整除。

    思路:

      用dp[i][j]表示长度为i,最后一个数是j的序列有多少种。然后递推就可以了。

    代码:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 
     5 using namespace std;
     6 
     7 typedef __int64 ll;
     8 const ll MOD = (ll)1e9+7;
     9 
    10 ll dp[2030][2020];
    11 int n, k;
    12 
    13 int main() {
    14     #ifdef Phantom01
    15         freopen("D.txt", "r", stdin);
    16     #endif // Phantom01
    17 
    18     while (scanf("%d%d", &k, &n)!=EOF) {
    19         memset(dp, 0, sizeof(dp));
    20         for (int i = 1; i <= k; i++)
    21             dp[1][i] = 1;
    22         for (int i = 1; i < n; i++) {
    23             for (int j = 1; j <= k; j++) {
    24                 for (int l = j; l <= k; l += j)
    25                     dp[i+1][l] = (dp[i+1][l]+dp[i][j])%MOD;
    26             }
    27         }
    28         ll ans = 0;
    29         for (int i = 1; i <= k; i++)
    30             ans = (ans+dp[n][i])%MOD;
    31 
    32         printf("%d
    ", (int)ans);
    33     }
    34 
    35     return 0;
    36 }
    View Code
  • 相关阅读:
    hihocoder 1038
    hihocoder 1039
    poj 2774
    bzoj 4690&&4602
    poj 2417
    STL
    poj 1026
    poj 1064
    poj 1861(prim)
    poj 1129
  • 原文地址:https://www.cnblogs.com/Phantom01/p/3650871.html
Copyright © 2011-2022 走看看