您的位置:首页 > 编程语言 > Java开发

2019 GDUT Spring Training IV (Div.2) (dp,)

2019-03-30 22:34 323 查看

D. Mashmokh and ACM

题目链接:http://codeforces.com/group/NVaJtLaLjS/contest/240952/problem/D
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
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).

Examples

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].

题目大意:

从1到n中找出能被ai+1能被ai整除,且长度为k的方案数。

题目思路:

dp:
dp[i][j]表示长为i,以j结尾的方案数
求dp[i+1][j]=∑dp[i][k],k为j的因数;
初始化dp[1][ j ] =1;
i→k;
j→n;
o→o*j<=n;
dp[i+1][o*j]+=dp[i][j];
最后统计dp[k][i]和即可。
代码:

#include <bits/stdc++.h>
using namespace std;
#define maxn 100005
#define ll long long
const ll mod=1e9+7;
long long dp[2005][2005];
int n,k;
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
d'p[1][i]=1;
}
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
for(int o=1;o*j<=2000;o++){
dp[i+1][o*j]+=dp[i][j];
dp[i][o*j]%=mod;
}
}
}
ll ans=0;
for(int i=1;i<=n;i++){
ans+=dp[k][i];
ans%=mod;
}
cout<<ans<<"\n";

return 0;
}

设dp[i]为前i项已经确定第i项的方案数,
先初始化i(1→n):dp[i]=1;
t=j的倍数
t=j+j;
dp[j] = (dp[j]+dp[t])%MOD;
当k=1时,递推一遍;
当k=2时,递推一遍;

每次递推都加上后面可以接上的dp。
递推k-1次,后所有dp[i]加起来即是答案。
代码:

#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#define MOD 1000000007
using namespace std;

int main(){
int i, j, t;
int n, k;
int dp[2005];
scanf("%d%d", &n, &k);
for (i=1;i<=n;i++){
dp[i] = 1;
}
for (i=0;i<k-1;i++){
for (j=1;j<=n;j++) {
t=j+j;
while (t<=n){
dp[j]=(dp[j]+dp[t])%MOD;
t+=j;
}
}
}
for (dp[0]=0,i=1;i<=n;i++) {
dp[0]=(dp[0]+dp[i])%MOD;
}
printf("%d\n", dp[0]);
return 0;
}

之后的再补

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: