Title link: https://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=1539
Topic
The perfect sequence is defined as the length of l, the maximum value does not exceed n and in ascending order, and then the previous one is a factor of the next one.
Give you n and l, and ask how many perfect sequences you have to modulo 1e9+7
Ideas
dp preprocessing, dp[i][j] means the length is i, the last digit is the number of perfect sequences like j, k starts from j and then j*2, j*3, until the upper limit n, here k can be used as the next bit of a perfect sequence with j at the end, so dp[i][k] is the accumulation of dp[i-1][j](1<=j<=n).
Finally, a perfect sequence with the maximum length of l not exceeding n is required, then it is the accumulation of dp[l][i] (1<=i<=n).
ac code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9 + 7;
int dp[2021][2021];
int main(){
int t; scanf("%d", &t);
for(int i = 1; i <= 2020; i ++) dp[1][i] = 1;
for(int i = 2; i <= 2020; i ++){
for(int j = 1; j <= 2020; j ++){
for(int k = j; k <= 2020; k += j){
dp[i][k] = (dp[i][k] + dp[i - 1][j]) % mod;
}
}
}
while(t --){
int n, l;
scanf("%d%d", &n, &l);
int ans = 0;
for(int i = 1; i <= n; i ++) ans += dp[l][i], ans %= mod;
printf("%d\n", ans);
}
return 0;
}