Digital DP Primer: bzoj1833: [Zjoi2010]count digit Count

Source: Internet
Author: User

Worshipped the Cai God .... And then suddenly remembered something and then filled it with a half-year-ago Pit = =

The first way of life is to write your own digital DP ... Well, I used to look at the puzzle, and then I didn't know why. >_<

Digital DP Introduction:

Http://wenku.baidu.com/link?url=9OS5Ybpw5wx00ahrH8ED2oyIlR1uWwrxT8N4pEg27GgBt2T2hLe4sd_h1rmpY7P0HmeHIEDw9h6_ K98dphhjomhd2tpkcs8w1x8cc_dkpp_

Next is the title address:

http://www.lydsy.com:808/JudgeOnline/problem.php?id=1833

Test instructions is quite obvious.

First of all, I can use f[i,j,k] to indicate that there is a number of I-digit and leading to K in a total of how many numbers J (0<=j<=9) ...

Then Konjac Konjac don't want to be too troublesome (too weak) ... Simply split the 1~9 into 9 times a time to ....

Because the title is [L,r], the answer is [0,r]-[0,l-1] ...

Suppose that the number of 0~x that is currently being asked is how many digits num ...

First, X has a w digit, The x is split into a w bit (the first bit is the lowest bit) there is an array h inside, and then in the processing of x after the I-bit combination is what number (that is, the W suffix of x)

Use pre[i] to indicate the number of I in the I-digit number

Then assume that the processing to the first (i) bit from the highest bit (W) is enumerated):

1, first consider the situation on the following position:

When the number of the I-digit is less than h[i], there is a h[i] (0~h[i]-1), all the numbers after this time can be selected (no matter what number is selected after X), so the total number +=h[i]*pre[i-1] (The number of digits in a bit after each of the current bits can be contributed to the total number)

2, consider the situation of the current position:

If the current bit maximum can take the number =num, because the previous digits are the largest, after the number can not exceed the range of X (if any one of the previous digits is less than the maximum value, then the number may be arbitrarily selected, it has been calculated by the above steps), so can contribute (the value of the next suffix is now + 1 (because there is a case that is followed by a full selection of 0)) answer ....

If the current bit maximum can take the number of <num, then regardless of how to take, the current bit will not contribute any number ...

Konjac Konjac Pull half a day finally determine oneself is the language died early >_< ....

The following is the more ugly code tat

If the current bit is the maximum number of >num, then when the number is num, the number of the back can be arbitrarily taken, and each case will contribute an extra number (that is, the current bit of this), so the total number of +=10^ (i-1)

1 var2Pre,orz,h,sum:Array[0.. -] ofInt64;3ANS,ANS1:Array[0..9] ofInt64;4 I,j,k,n,m,mid:longint;5 L,r,tot,tot1,l1,r1,x,w1,w2:int64;6 procedureMahoshojo (x,num,w:int64);7 varI:longint;anss:int64;8 begin9anss:=0;Ten    fori:=1  toW DoH[i]:=xDivorz[i-1]MoD Ten; One    fori:=1  toW DoSum[i]:=xMoDOrz[i]; A    forI:=wDownto 1  Do -   begin -Inc (anss,pre[i-1]*h[i]); the     ifH[i]>num ThenInc (anss,orz[i-1]); -     ifH[i]=num ThenInc (anss,sum[i-1]+1); -   End; -ans[num]:=ans[num]+Anss; +tot:=tot-Anss; - End; + begin Apre[1]:=1; atorz[0]:=1; -    fori:=1  to  -  Doorz[i]:=orz[i-1]*Ten; -    fori:=2  to  -  Dopre[i]:=pre[i-1]*Ten+orz[i-1]; - readln (l,r); - Dec (l); -tot:=1; in   ifL>0  Then -   begin tol1:=l; +      whileL1>0  Do beginInc (W1); l1:=l1Div Ten End; -      fori:=1  toW1-1  DoInc. (Tot, (orz[i]-orz[i-1])*i); the     ifW1>1  ThenInc (Tot,w1* (l-orz[w1-1]+1))Elsetot:=l+1; *   End $   ElsePanax Notoginsengw1:=1; -r1:=R; the    whileR1>0  Do beginInc (W2); r1:=r1Div Ten End; +tot1:=1; A    fori:=1  tow2-1  DoInc (TOT1, (orz[i]-orz[i-1])*i); the   ifW2>1  ThenInc (TOT1,W2* (r-orz[w2-1]+1))Elsetot1:=r+1; + //writeln (W2, ': ', Tot1, ', W1, ': ', tot); -    fori:=1  to 9  Do $ Mahoshojo (L,I,W1); $    fori:=1  to 9  Doans[i]:=-Ans[i]; -ans[0]:=tot; - //writeln (', tot); thetot:=tot1; - //writeln ('!!! ', tot1);Wuyi    fori:=1  to 9  Do the Mahoshojo (R,I,W2); -ans[0]:=tot-ans[0]; Wu    fori:=0  to 8  Do Write(Ans[i],' '); -Writeln (ans[9]) About End.
View Code

Words remember that there is a gdoi problem .... Requires the exact opposite = = ... Give you the number of 1~ in a number, ask to determine whether there is this number ...

Anyway Konjac konjac Visual only two points to make tat .... It's not TLE2333 to play anyway.

Four months without touching the keyboard tat ... There's a bit left in the brain, but the code is back to two years ago >_<

Words to review before the time to pits obviously pattern for the big dead ... YCL: What kind of student are you like?

Digital DP Primer: bzoj1833: [Zjoi2010]count digit Count

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.