Number of Scoi2009windy

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.