1033: Interleaving and time limit: 10000mssingle point time limit: 1000msmemory limit: 256MBDescribe
Given a number x, set it decimal show from high to low number of digits is a0, a1, ..., an - 1, define interleaving and functions:
F (x) = a0- a1 + a2-... + (-1)n -1aN -1
For example:
F (3214567) = 3-2 + 1-4 + 5-6 + 7 = 4
Given l, R, K, in the [l, R] interval, all F(x) = The and of the x of K, i.e.:
Input
Input data only one row contains three integers,l, R, K(0≤ l ≤ r ≤10), | K| ≤100).
Output
The output line is an integer representing the result, considering that the answer may be large and the output modulo 9 + 7.
Tips
For the sample, the number of satisfied conditions is 110 and 121, so the result is 231 = 110 + 121.
A more diverse example:
Input |
4344 3214567 3 |
Output |
611668829 |
Input |
404491953 1587197241 1 |
Output |
323937411 |
Input |
60296763086567224 193422344885593844 10 |
Output |
608746132 |
Input |
100 121-1 |
Output |
120 |
-
Sample input
-
100 121 0
-
Sample output
-
231
#include <iostream>#include<cstdio>#include<cstring>using namespaceStd;typedefLong LongLL;Const intMOD = (int) 1e9 +7;inta[ -]; LLBase[ -];intK, Len;structp{LL num, sum; P (LL a=-1, LL b=0): Num (a), sum (b) {}} dp[ -][ the][3]; P DFS (intCurintStintPosBOOLlimit) { if(Cur <1)returnP (st = = the+ K,0); if(!limit && pos!=0&& Dp[cur][st][pos].num! =-1)returnDp[cur][st][pos]; intEnd = limit? A[cur]:9; P ret (0,0); intNew_st, New_pos; for(intI=0; i<=end; i++) { if(pos==0&& i==0) {New_pos=POS; New_st=St; } Else { if(pos<2) New_pos = pos +1; ElseNew_pos = pos-1; if(New_pos &1) New_st = st +i; ElseNew_st = St-i; } p P= DFS (cur-1, New_st, New_pos, limit&&i==end); Ret.num= (ret.num + p.num)%MOD; Ret.sum= (Ret.sum + (p.num * i)% MOD *Base[cur]% MOD + p.sum)%MOD; } if(!limit && pos!=0) Dp[cur][st][pos] =ret; returnret;}intf (LL x) {len=0; while(x) {a[++len] = x percentTen; X/=Ten; } returnDFS (Len, the,0,1). Sum;}voidInit () {Base[1] =1; for(intI=2; i<= +; i++) { Base[I] =Base[I1] *Ten%MOD; }}intMain () {Init (); LL L, R; scanf ("%lld%lld%d", &l, &r, &k); printf ("%lld\n", (f (R)-F (L-1) + MOD)%MOD); return 0; }
Hiho 1033--Interleaved and "digital DP"