Test instructions: Given two numbers, the number of times in the Q interval [a, b] 0~9 appears respectively. A,b<=10^18
The most bare digital DP bar: At first, there was no memory of the tle. Tat
We can find out the interval [0,b], minus the interval [0,a].
With DFS implementation, record flag (whether the filled bit is coincident with the boundary), zero (currently in prefix 0)
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5#include <ctime>6#include <queue>7 using namespacestd;8 9typedefLong LongLL;Ten Const intn= -; One intc[n][n][2][2],d[n],sum[n]; A LL Bit[n],ret[n]; - -LL g (intNowintXintFlagintzero) the { - if(c[now][x][flag][zero]!=-1)returnC[now][x][flag][zero]; - if(x==0)return 0; -LL ans=0; + if(flag) - { + for(intI=0; i<d[x];i++) A { atAns+=g (now,x-1,0, Zero & (i==0)); - if(I==now &&!) (i==0&& zero)) ans+=bit[x-1]; - } -Ans+=g (now,x-1,1, Zero && (d[x]==0)); - if(Now==d[x] &&! (now==0&& zero)) ans+=ret[x-1]; - } in Else - { to for(intI=0; i<=9; i++) + { -Ans+=g (now,x-1,0, Zero & (i==0)); the if(I==now &&!) (i==0&& zero)) ans+=bit[x-1]; * } $ }Panax Notoginseng //printf ("Now%d x%d flag%d Zero%d =%d\n", Now,x,flag,zero,ans); -c[now][x][flag][zero]=ans; the returnans; + } A the voidSolve (LL x,ll tmp) + { -memset (D,0,sizeof(d)); $memset (c,-1,sizeof(c)); $ intL=0; LL y=x; - while(y) - { theD[++l]= (int) (y%Ten); -Y/=Ten;Wuyi } the for(intI=0; i<= -; i++) ret[i]=x%bit[i]+1; - for(intI=0; i<=9; i++) sum[i]+=g (i, -,1,1)*tmp; Wu } - About intMain () $ { - //freopen ("a.in", "R", stdin); -Freopen ("dream.in","R", stdin); -Freopen ("Dream.out","W", stdout); ALL A, B;intx; +scanf"%lld%lld",&a,&B); thememset (SUM,0,sizeof(sum)); -bit[0]=1; $ for(intI=1; i<= -; i++) bit[i]=bit[i-1]*Ten; theSolve (A-1,-1); theSolve (B,1); the for(intI=0; i<=9; i++) printf ("%d", Sum[i]); the return 0; -}
"Dream Counting, 2006 dec-Number of Dreams" digital DP