Codeforces Round #240 (Div. 2) D


D. Mashmokh and ACM

 

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
input
6 4
output
39
input
2 1
output
2

 

 题意:给出一组数列,问满足数列递增且前一个元素能整除后一个元素的数列一共有多少种。

 sl:赤裸裸的dp,比赛时叫C整的快没时间了,十分钟敲了下交了一发wa了原来忘记mod1e9了。

dp方程:  dp[i][j]+=dp[i-1][k]  (j%k==0) 只要预处理因子就可以了。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<vector>
 5 using namespace std;
 6 const int MAX = 2000+10;
 7 const int MOD = 1e9+7;
 8 int dp[MAX][MAX];
 9 vector<int> v[MAX];
10 void init()
11 {
12     memset(dp,0,sizeof(dp));
13     for(int i=1;i<MAX;i++) dp[1][i]=1;
14     for(int i=1;i<MAX;i++)
15     {
16         for(int j=1;j<=i;j++)
17         {
18             if(i%j==0) v[i].push_back(j);
19         }
20     }
21 }
22 int main()
23 {
24     int n,k;
25     init();
26     scanf("%d %d",&n,&k);
27     for(int j=1;j<=n;j++)
28     for(int i=2;i<=k;i++)
29     {
30         for(int m=0;m<v[j].size();m++)
31         {
32             dp[i][j]=(dp[i][j]+dp[i-1][v[j][m]])%MOD;
33         }
34     }
35     int ans=0;
36     for(int i=1;i<=n;i++) ans=(ans+dp[k][i])%MOD;
37     printf("%d\n",ans%MOD);
38     return 0;

39 } 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2014-04-07 11:39  acvc  阅读(210)  评论(0编辑  收藏  举报