Digital DP
Orz Iwtwiioi
Learn a bit about the new posture of using memory search to catch a problem ... But did not learn tat, and then dig a hole (mom eggs to me, the digital DP is a god hole ...) sigh
1 //Bzoj 18332#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <iostream>6#include <algorithm>7 #defineRep (i,n) for (int i=0;i<n;++i)8 #defineF (i,j,n) for (int i=j;i<=n;++i)9 #defineD (i,j,n) for (int i=j;i>=n;--i)Ten using namespacestd; OnetypedefLong LongLL; A LL Getint () { -LL v=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9') {if(ch=='-') sign=-1; Ch=GetChar ();} the while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*=Sign ; - } - /*******************tamplate********************/ + - +LL f[ -],c[ -],a[ -],p[ -]; ALL DFS (intXintDigintFrontintLine ) { at if(!x)return 0; - if(!front &&!line && f[x]!=-1)returnF[x]; -LL last= (line a[x]:9), tot=0; -F (I,0, last) { - if(Front && i==0) Tot+=dfs (x1, Dig,1, line&&i==Last ); - Else if(i==dig) { in if(I==last && Line) tot+=c[x-1]+1+dfs (x1, Dig,0, Line && i==Last ); - Elsetot+=p[x-1]+dfs (x1, Dig,0, Line && i==Last ); to } + ElseTot+=dfs (x1, Dig,0,line&& i==Last ); - } the if(!front &&!line) f[x]=tot; * returntot; $ }Panax Notoginseng ll Getans (ll x,ll dig) { -memset (f,-1,sizeoff); theLL t=x;intlen=0; + while(t) a[++len]=t%Ten, t/=Ten, c[len]=c[len-1]+a[len]*p[len-1]; A returnDFS (Len,dig,1,1); the } + intMain () { - //freopen ("Input.txt", "R", stdin); $LL a=getint (), b=getint (); $p[0]=1; F (I,1, the) p[i]=p[i-1]*Ten; -Rep (I,9) printf ("%lld", Getans (B,i)-getans (a1, i)); -printf"%lld\n", Getans (b,9)-getans (A-1,9)); the return 0; -}
View Code
"Bzoj" "1833" "ZJOI2010" count number counts