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 Input
Input
3 2
Output
5
Input
6 4
Output
39
Input
2 1
Output
2
Hint
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
思路:dp[i][j]表示长度为i,末尾元素为j的种类数。
# include<cstdio>
# include<iostream>
# include<string.h>
# include<cmath>
using namespace std;
const long long int MOD=1000000007;
int dp[2000+5][2000+5];
int main()
{
memset(dp,0,sizeof(dp));
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
dp[1][i]=1;
for(int i=1;i<=k-1;i++)
{
for(int j=1;j<=n;j++)
{
for(int t=1;j*t<=n;t++)
{
dp[i+1][j*t]+=dp[i][j];
dp[i+1][j*t]%=MOD;
}
}
}
long long int s=0;
for(int i=1;i<=n;i++)
s+=dp[k][i];
s%=MOD;
cout<<s<<endl;
return 0;
}
一道来自Codeforces的编程任务,要求找到所有长度为k且每个数都能被下一个数整除的序列(良好序列)的数量。给定整数n和k,计算这些序列的数量并取模10^9+7。题目提供了样例输入和输出,以及解题思路。

204

被折叠的 条评论
为什么被折叠?



