zoukankan      html  css  js  c++  java
  • Codeforces Round #240 (Div. 1) B. Mashmokh and ACM DP

                                                 B. Mashmokh and ACM
                                                                                                time limit per test
                                                                                                1 second
                                                                                                memory limit per test
                                                                                                256 megabytes

    Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.

    A sequence of l integers b1, b2, ..., bl (1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally  for all i (1 ≤ i ≤ l - 1).

    Given n and k find the number of good sequences of length k. As the answer can be rather large print it modulo 1000000007(109 + 7).

    Input

    The first line of input contains two space-separated integers n, k (1 ≤ n, k ≤ 2000).

    Output

    Output a single integer — the number of good sequences of length k modulo 1000000007 (109 + 7).

    Sample test(s)
    input
    3 2
    output
    5
    Note

    In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].

    题意:给你一个N,K,  表示从1到n,选取长度为k的序列A满足  Ai整除Ai-1

    题解:dp[i][j]表示长度为j是最大为i的序列方案数

    //1085422276
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<queue>
    #include<cmath>
    #include<map>
    #include<bitset>
    #include<set>
    #include<vector>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define meminf(a) memset(a,127,sizeof(a));
    #define memfy(a) memset(a,-1,sizeof(a))
    #define TS printf("111111
    ");
    #define FOR(i,a,b) for( int i=a;i<=b;i++)
    #define FORJ(i,a,b) for(int i=a;i>=b;i--)
    #define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
    #define mod 1000000007
    #define maxn 2005
    inline ll read()
    {
        ll x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9')
        {
            if(ch=='-')f=-1;
            ch=getchar();
        }
        while(ch>='0'&&ch<='9')
        {
            x=x*10+ch-'0';
            ch=getchar();
        }
        return x*f;
    }
    //****************************************
    ll  dp[maxn][maxn];
    
    int main()
    {
    
        int n=read(),m=read();
        mem(dp);
        FOR(i,1,n)dp[i][1]=1;
        FOR(k,1,m-1)
        FOR(i,1,n)
        { if(dp[i][k])
             for(int j=i;j<=n;j+=i)
             {
                 dp[j][k+1]=(dp[j][k+1]+dp[i][k])%mod;
             }
        }
        ll ans=0;
        FOR(i,1,n)ans=(ans+dp[i][m])%mod;
        cout<<ans<<endl;
        return 0;
    }
    代码
  • 相关阅读:
    Ubuntu
    VSCode
    VSCode
    Astyle
    Qt
    待办
    Qt
    Qt
    Qt
    python pip常用命令、配置pip源
  • 原文地址:https://www.cnblogs.com/zxhl/p/4802281.html
Copyright © 2011-2022 走看看