Links: https://ac.nowcoder.com/acm/problem/21738 Source: Cattle-off network
Title Description
Beef array like this:
1: length n-
2: in every number between 1 to K
. 3: (! A% B = 0) for any number of consecutive two of A, B, A <= B and two conditions set up at least one
to ask a total number of array to meet the conditions of 1e9 + 7 modulo
1: length n-
2: in every number between 1 to K
. 3: (! A% B = 0) for any number of consecutive two of A, B, A <= B and two conditions set up at least one
to ask a total number of array to meet the conditions of 1e9 + 7 modulo
Enter a description:
Input two integers n-, K
. 1 ≤ n-≤ 10
. 1 ≤ K ≤ 100000
Output Description:
An integer output
Specific ideas:
DP [i] [j] represents the situation prior to the legitimate sequence i, j is the i-th bit time.
If violence is three, then certainly T, we can record the total value of the second for loop, and then go to the noncompliance to remove. If the condition 1, we accumulated the previous count just fine.
For Condition 2, we first pre-out multiples of each number, and then subtract illegal situation on it.
AC Code:
1 #include<bits/stdc++.h> 2 using namespace std; 3 # define ll long long 4 # define inf 0x3f3f3f3f 5 const int maxn = 2e5+100; 6 const int N = 15; 7 const int mod = 1e9+7; 8 ll dp[N][maxn]; 9 vector<ll>sto[maxn]; 10 int main(){ 11 int n,k; 12 scanf("%d %d",&n,&k); 13 for(int i=1;i<=k;i++){ 14 dp[1][i]=1; 15 } 16 for(int i=1;i<=k;i++){ 17 for(int j=2;j*i<=k;j++){ 18 sto[i].push_back(i*j); 19 } 20 } 21 for(int i=2;i<=n;i++){ 22 ll sum=0 ; 23 is for ( int J = . 1 ; J <= K; J ++) {SUM = (SUM + DP [I- . 1 ] [J])% MOD;} 24 LL tmp = 0 ; 25 for ( int J = . 1 ; J <= K; J ++ ) { 26 is DP [I] [J] = (DP [I- . 1 ] [J] + tmp)% MOD; 27 tmp = (tmp + DP [I- . 1 ] [J]) % MOD; 28 LL ANS = (SUM-tmp + MOD)% MOD; // where the operator has had to delete 29 for ( int W = 0 ; W <STO [J] .size (); W ++ ) { 30 ans=(ans-dp[i-1][sto[j][w]]+mod)%mod; 31 } 32 dp[i][j]=(dp[i][j]+ans)%mod; 33 } 34 } 35 ll ans=0; 36 for(int i=1;i<=k;i++){ 37 ans=(ans+dp[n][i])%mod; 38 } 39 printf("%lld\n",ans); 40 return 0; 41 }