How many O ' s?
Test instructions is the number of the number within the interval of 0, such as 100 has two 0.
Digital DP Bar, Dp[i][j][k], I clearly indicates the current position, J indicates the number of 0 found, and K indicates the number of 0 to find. Because the number of 0 in the number of up to 32, so you can enumerate 32 K cases, with the digital DP to find.
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespacestd;#definell Long Longintdig[ -];ll dp[ +][ +][ +];intBigcnt;ll DFS (intPosintCntintFlagintLim) {if(pos = =-1)returnCNT = =0; if(CNT <0)return 0; if(!flag &&!lim && dp[pos][cnt][bigcnt]! =-1)returndp[pos][cnt][bigcnt]; intEnd = Lim? Dig[pos]:9; LL ret=0; for(inti =0; I <= End; i++) { if(Flag &&!i) ret + = DFS (pos-1, bigcnt,1, Lim && (i = =End)); Else if(Flag && i) ret + = DFS (pos-1, bigcnt,0, Lim && (i = =End)); Else if(!flag && i) ret + = DFS (pos-1Cnt0, Lim && (i = =End)); Else if(!flag &&!i) ret + = DFS (pos-1, CNT-1,0, Lim && (i = =End)); } if(!lim &&!flag) dp[pos][cnt][bigcnt] =ret; returnret;} ll func (ll num) {LL ret=0; if(num = =-1)return-1; intn =0; while(num) {dig[n+ +] = num%Ten; Num/=Ten; } for(inti =1; I <= +; i++) {bigcnt=i; RET+ = i * DFS (n-1I1,1); } returnret;}intMain () {ll A, B; Memset (DP,-1,sizeof(DP)); while(~SCANF ("%lld%lld", &a, &b)) {if(A <0) Break; printf ("%lld\n", func (b)-Func (A-1)); }}
UVA-11038 how many O ' s? (Digital DP)