[hdu2089] [No 62]

Source: Internet
Author: User

hdu2089 idea Digital DP template problem. Search from high to low, use POS to record the current position, LST records the number of the previous position, BZ records whether the last position is 6,limit to record whether the previous position reached the upper bound (if reached, it will need to process the upper bound of the current position) code
#include <cstdio> #include <iostream> #include <cstring>using namespace std;typedef long Long ll;ll    Read () {ll x=0,f=1;char C=getchar (); while (c< ' 0 ' | |        C> ' 9 ') {if (c== '-') f=-1;    C=getchar ();        } while (c>= ' 0 ' &&c<= ' 9 ') {x=x*10+c-' 0 ';    C=getchar (); } return x*f;}    int f[20][2];int a[20];int dfs (int pos,int lst,int bz,int limit) {if (pos==0) return 1;    if (f[pos][bz]!=-1) return F[POS][BZ];    int up=limit?a[pos]:9;    int ans=0; for (int i=up;i>=0;--i) {if (i==4| | (lst==6&&i==2))        Continue    Ans+=dfs (Pos-1,i,i==6,limit&&i==up);    } if (!limit) F[pos][bz]=ans; return ans;}    int solve (int x) {memset (a,0,sizeof (a));    memset (F,-1,sizeof (f));        while (x) {a[++a[0]]=x%10;    x/=10; } return Dfs (a[0],0,0,1);}    int main () {int l,r;        while (1) {l=read ();        R=read ();        if (!l&&!r) break;    printf ("%d\n", Solve (R)-solve (L-1)); }   return 0;} 

[hdu2089][]

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.