Digital DP, not really ...
The Calc function is divided into three parts:
The first part: statistics of the highest bit of 0, or the number of the most than the highest number of digits
The second part: Statistics the highest bit is 1 to a[len]-1, the direct call array can
The third part: the statistic and the X front (len-i) bit is same, but the remaining different satisfies the condition the number
Here's a trick, which is to be practical, just like the origin of imaginary numbers.
f[i,0] If there is no point in looking directly at it, will that number start at 0?
But if it does, f[i,j]:=f[i,j]+f[i-1,k]j can use it very well.
Or we can take f[i,j] as a string of length I, the number of strings that satisfy a condition with the first character J
Code:
1 varI,j,k,x,y:longint;2F:Array[-1.. the,-1.. the] ofLongint;3 functionCalc (x:longint): Longint;4 varI,j,len:longint;5 st:string;6A:Array[0.. the] ofLongint;7 begin8 ifx=0 ThenExit0);9 str (x,st);Tenlen:=Length (ST); Onecalc:=0; A fori:=1 toLen DoA[i]:=ord (st[len+1-I.])- -; - fori:=1 tolen-1 Do - forj:=1 to 9 Do the Inc (Calc,f[i,j]); - fori:=1 toa[len]-1 Do - Inc (Calc,f[len,i]); - fori:=len-1 Downto 1 Do + begin - forj:=0 toa[i]-1 Do + ifABS (a[i+1]-J) >=2 ThenInc (Calc,f[i,j]); A ifABS (a[i+1]-a[i]) <2 ThenBreak ; at End; - End; - proceduremain; - begin - fori:=0 to 9 Dof[1, i]:=1; - fori:=2 to Ten Do in forj:=0 to 9 Do - fork:=0 to 9 Do to ifABS (J-K) >=2 Thenf[i,j]:=f[i,j]+f[i-1, K]; + readln (x, y); -Writeln (Calc (y+1)-Calc (x)); the End; * begin $ main;Panax Notoginseng End.
View Code