Test instructions
F[0]=0,f[i]=f[i-1]+a or B.
The seed number of the sequence satisfying l<=∑f[n]<=r
N<100. |a|,|b|<=10000. | l|,| R|<1e9
Solution
is actually a knapsack problem.
When a=b, sequence 0 a a+a and 0 B b+b actually count different sequences = =, giant pits
#include <iostream>#defineLL Long Longusing namespacestd;Const intMOD = (int) 1e9 +7;Const intK the; LL N, A, B, L, R; LL dp[109][109*109];intMain () {dp[0][0] =1; for(inti =1; I <= M; i++) for(intj =0; J <= (I * (i-1) /2); J + +) {Dp[i][j]= (Dp[i-1][J] + dp[i][j])%MOD; Dp[i][j+ i] = (Dp[i-1][J] + dp[i][j + i])%MOD; } for(inti =1; I <= M; i++) for(intj = (i +1) * I/2-1; J >=0; j--) Dp[i][j]= (Dp[i][j +1] + dp[i][j])%MOD; while(Cin >> N >> a >> b >> L >>R) {if(A >b) Swap (A, b); LL s= A * (1+ N) * N/2; if(s <= R && b! =a) {LL nl= (l-s)/(b-a), nr = (r-s)/(B-A) +1; if((l-s)% (b-a)! =0) nl++; if(L-s <=0) NL =0; if(nl > (N +1) *n/2) NL = (N +1) * N/2+1; if(Nr > (N +1) *n/2) NR = (N +1) * N/2+1; cout<< (mod + dp[n][nl]-dp[n][nr])% mod <<Endl; } Else if(S >= L && s <= R && b = =a) {LL ans=1; for(inti =1; I <= N; i++) ans= (ans *2) %MOD; cout<< ans <<Endl; } Elsecout<<0<<Endl; } return 0;}
View Code
WHU 1579 Big data (DP)