CodeForces 414B Mashmokh and ACM

 

->题目链接

 

  定义一个数组dp,dp[ i ][ j ]表示以数值 i 结尾的、长度为 j 的good序列。

  容易知道dp[ i ][1](1≤i≤n) 为1。

  每求得一个 i,j 对应的dp[ i ][ j ],就把这个值加在

dp[ p*i ][ j+1 ],dp[ p*i ][ j+2 ],…,dp[ p*i ][ k ](p>1 且 p*i ≤ n)

上,最后,答案为sum(dp[ q ][k]),1≤q≤n。

 

 

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <map>
 4 #include <vector>
 5 #include <functional>
 6 #include <string>
 7 #include <cstring>
 8 #include <queue>
 9 #include <stack>
10 #include <set>
11 #include <cmath>
12 #include <cstdio>
13 using namespace std;
14 #define IOS ios_base::sync_with_stdio(false)
15 #define TIE std::cin.tie(0)
16 #define MAX2(a,b) (a>b?a:b)
17 #define MAX3(a,b,c)  (a>b?(a>c?a:c):(b>c?b:c))
18 typedef long long LL;
19 typedef unsigned long long ULL;
20 const int INF=0x3f3f3f3f;
21 const double PI=4.0*atan(1.0);
22 const int MOD=1000000007;
23 int n,k,dp[2005][2005],ans;
24 
25 int main()
26 {
27     //while(~scanf("%d%d",&n,&k))
28         scanf("%d%d",&n,&k);
29         ans=0;
30         for(int i=1;i<=n;i++){
31             dp[i][1]=1;
32             for(int j=i;j<=n;j+=i){
33                 for(int p=2;p<=k;p++){
34                     dp[j][p]+=dp[i][p-1];
35                     if(dp[j][p]>MOD) dp[j][p]-=MOD;
36                 }
37             }
38         }
39         for(int i=1;i<=n;i++){
40             ans+=dp[i][k];
41             if(ans>MOD) ans-=MOD;
42         }
43         printf("%d\n",ans);
44     //}
45 }
View Code

 

posted @ 2016-08-05 14:23  Cumulonimbus  阅读(128)  评论(0编辑  收藏  举报