http://codeforces.com/problemset/problem/414/B
题目大意:
题意:一个序列B1,B2...Bl如果是好的,必须满足Bi | Bi + 1(a | b 代表a整除b), 求长度为K,元素大小小于等于N的序列个数
思路:f[i][j] 代表在序列的第i位,当前数字为j的方案数
1 #include<cstdio> 2 #include<cmath> 3 #include<algorithm> 4 #include<cstring> 5 #include<iostream> 6 const int Mod=1000000007; 7 int f[5005][5005]; 8 int n,K; 9 int read(){ 10 int t=0,f=1;char ch=getchar(); 11 while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} 12 while ('0'<=ch&&ch<='9'){t=t*10+ch-'0';ch=getchar();} 13 return t*f; 14 } 15 int main(){ 16 n=read();K=read(); 17 for (int i=1;i<=n;i++) 18 f[1][i]=1; 19 for (int i=2;i<=K;i++) 20 for (int j=1;j<=n;j++){ 21 for (int k=1;k<=sqrt(j);k++) 22 if (j%k==0){ 23 f[i][j]=(f[i][j]+f[i-1][k])%Mod; 24 if (k*k!=j) 25 f[i][j]=(f[i][j]+f[i-1][j/k])%Mod; 26 } 27 } 28 int ans=0; 29 for (int i=1;i<=n;i++) 30 ans=(ans+f[K][i])%Mod; 31 printf("%d ",ans); 32 return 0; 33 }