您的位置:首页 > 其它

codeforces-414B-Mashmokh and ACM

2015-11-04 14:24 316 查看

codeforces-414B-Mashmokh and ACM

[code]                    time limit per test1 second     memory limit per test256 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).

input

3 2

output

5

input

6 4

output

39

input

2 1

output

2

Note

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

题目链接:cf-414B

题目大意:问在1~n中有多少个序列满足后一项能整除前一项。

题目思路:dp。dp[i][j] 表示在1~i中,序列以j结尾有多少种方法数满足条件。

以 1,2,3,4,5为例。

长度为1:[1],[2],[3],[4],[5]

长度为2:[1,1],[1,2],[1,3],[1,4],[1,5],[2,2],[2,4],[3,3],[4,4][5,5]。

长度为3……

以下是代码:

[code]#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
#define MOD 1000000007
int dp[3000][3000];
int main(){
    int n,k;
    cin >> n >> k;
    for (int i = 0; i <= n; i++)    //初始化,长度为1,以i结尾的方法数为1
        dp[1][i] = 1;
    for (int i = 1; i < k; i++)      //遍历序列长度
    {
        for (int j = 1; j <= n; j++)    //以j结尾
        {
            for (int m = j; m <= n; m += j)  
            {
                dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD;
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ans = (ans + dp[k][i]) % MOD;
    }
    cout << ans << endl;
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: