Digital DP Advanced (hdu2089,3652)

Source: Internet
Author: User

The previous article has already talked about how to seek the special number in 1-r, this blog is to say some advanced operation;

Read the example directly (hdu2089):

(The topic is Chinese, I will not write the careless)

The biggest difference between this problem and hdu3555 is that L is defined, no longer starts with 1;

To solve this problem is also very simple, using the prefix and the idea, first calculate the number of 1-L-1 special number, in the calculation of the number of l-r, subtraction is the answer;

Attach the Ugly code:

1#include <cstdio>2#include <iostream>3 using namespacestd;4 #defineint long Long5 Const intmaxn= -;6 intn,r,t,degit[maxn],dp[maxn][maxn],t2,l;7 intDfsintPosintPreBOOLlimit)8 {9     if(pos==0)return 1;Ten     if(!limit && dp[pos][pre]! =0) One     { A         returnDp[pos][pre]; -       } -     intup=9; the     if(limit) up=Degit[pos]; -     intans=0; -      for(intI=0; i<=up;++i) -     if(pre==6&&i==2|| i==4) +         Continue; -     Else +     { AAns+=dfs (pos-1,i,limit&& (i==Degit[pos])); at     } -     if(!limit) -     { -Dp[pos][pre] =ans; -     } -     returnans; in } - voidSolveintYintx) to { +t=0; -     intxx=x; the      while(x>0) *     { $++T;Panax Notoginsengdegit[t]=x%Ten; -x=x/Ten; the     } +     intAns2=dfs (T,0,1); At=0; the--y; +xx=y; -      while(y>0) $     { $++T; -degit[t]=y%Ten; -y=y/Ten; the     } -     intAns=dfs (T,0,1);Wuyiprintf"%lld\n", ans2-ans); the } - Main () Wu { -      while(cin>>l>>R) About     { $         if(l==0&&r==0)return 0; - solve (l,r); -     } -}
Example 2 (hdu3652):

Hand (Help) Move (you) translate (too lazy, do not want to write test instructions)

This problem is somewhat different from the above question, not only to meet 13, but also to divide 13;

The implementation is not difficult, as long as the search at the same time to record the number divided by 13 of the remainder;

How to pass it? This also test the primary School Olympiad, the remainder of the nature;

(4A and B and divided by the remainder of C (A, b two number divided by C in the absence of the remainder of the case), is equal to a B divided by the sum of the remainder of C (or this and divided by the remainder of C). For example at, the remainder of 16 divided by 5 is 3 and 1 respectively, so ( at+ -The remainder of the divided by 5 equals 3 +1=4。 Note: When the sum of the remainder is greater than the divisor, the remainder is equal to the sum of the remainder divided by the remainder of C. For example at, the remainder of 19 divided by 5 is 3 and 4 respectively, so ( at+ +) divided by 5 equals the remainder (3+4) divided by the remainder of 5. (5The product of A and B is divided by the remainder of C, which is equal to a B, divided by the product of the remainder of C (or the remainder of this product divided by C). For example at, the remainder of 16 divided by 5 is 3 and 1 respectively, so ( atX -) divided by 5 equals 3x1=3。 Note: When the remainder of the product is greater than the divisor, the remainder equals the remainder and the remainder of C. For example at, the remainder of 19 divided by 5 is 3 and 4 respectively, so ( atX +) divided by 5 equals the remainder (3X4) divided by the remainder of 5. Nature (4)(5) can be generalized to multiple natural numbers.

Too long don't want to see also doesn't matter, sum up is $ A \times 100+b \times 10+c$% $ d = a \times $%$ d+b \times, $%$ d +c $%$ d$;

What is the use of this property can let us at the time of delivery, as long as the remainder $\times 10$ plus now select the number of mod 13 can be, finally see if the conditions

Attach the Water code:

1#include <cstdio>2#include <iostream>3 using namespacestd;4 #defineint long Long5 Const intmaxn= -;6 intn,r,t,degit[maxn],dp[maxn][maxn][maxn][2];7 intDfsintPosintPreBOOLLimitintMoBOOLHaveintsum)8 {9     if(pos==0)Ten     { One         if(mo==0&&Have ) A         { -             return 1; -         } the         Else -             return 0; -     } -     if(!limit&&dp[pos][pre][mo][have]!=0)returnDp[pos][pre][mo][have]; +     intup=9; -     if(limit) up=Degit[pos]; +     intans=0; A      for(intI=0; i<=up;++i) at     if(pre==1&&i==3) -Ans+=dfs (pos-1,i,limit&& (I==degit[pos]), (mo*Ten+i)% -,1, sum*Ten+i); -     Else -Ans+=dfs (pos-1,i,limit&& (I==degit[pos]), (mo*Ten+i)% -, have,sum*Ten+i); -     if(!limit) dp[pos][pre][mo][have]=ans; -     returnans; in } - voidSolveintx) to { +t=0; -     intxx=x; the      while(x>0) *     { $++T;Panax Notoginsengdegit[t]=x%Ten; -x=x/Ten; the     } +printf"%lld\n", DFS (T,0,1,0,0,0)); A } the Main () + { -      while(cin>>R) $     { $ solve (r); -     } -}

And so the water over a blog;

The next article should say some of the changes + not much use of optimization (standing flag);

Digital DP Advanced (hdu2089,3652)

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.