Mashmokh and ACM
题面翻译
如果一个数列中,后一个数都能被前面一个数整除,那么就叫这个数列为好数列。输入 n , k n, k n,k,求数列中最大元素不超过 n n n,数列长度为 k k k 的好数列的种数(对 1000000007 1000000007 1000000007 取模)
由 @ROBOT233 提供翻译
输入格式
The first line of input contains two space-separated integers $ n,k (1<=n,k<=2000) $ .
输出格式
Output a single integer — the number of good sequences of length $ k $ modulo $ 1000000007 $ $ (10^{9}+7) $ .
样例 #1
样例输入 #1
3 2
样例输出 #1
5
样例 #2
样例输入 #2
6 4
样例输出 #2
39
样例 #3
样例输入 #3
2 1
样例输出 #3
2
#include <bits/stdc++.h>
using namespace std;
#define sf(x) scanf("%d",&x);
#define de(x) cout<<x<<" ";
#define Pu puts("");
typedef long long ll;
const int N=2e3+10,mod=1e9+7;
ll n,m,k;
ll ans;
ll f[N][N];//f[i][j]表示长度为j,最后一个数为i(也即是最大的数为i)时的种类数
vector<int>v[N];
void init(){//这个地方是看了题解后才明白的,需要预处理一下,求出每一个数的因子
//f[i][j]=f[tmp][j-1],这里的tmp是指所有i的因子个数
for(int i=1;i<=n;i++){
for(int j=1;j<=sqrt(i);j++){
if(i%j==0){
v[i].push_back(j);
if(j!=i/j) v[i].push_back(i/j);
}
}
}
}
int main(){
cin>>n>>k;
init();
for(int i=1;i<=n;i++) f[i][1]=1;//预处理
// for(int i=1;i<=n;i++){
// for(int j=2;j<=k;j++){
// for(int o=0;o<v[i].size();o++){
// f[i][j]=(f[i][j]+f[v[i][o]][j-1])%mod;
// }
// }
// }
for(int j=2;j<=k;j++){
for(int i=1;i<=n;i++){//两种写法都可以
for(int o=0;o<v[i].size();o++){
f[i][j]=(f[i][j]+f[v[i][o]][j-1])%mod;
}
}
}
for(int i=1;i<=n;i++){
ans=(ans+f[i][k])%mod;
}
de(ans)
return 0;
}