The number in the range [a, B] can be divided by the number of digits and the total number.
Train of Thought: to avoid repeated states, the number of enumerative digits and 1 ~ 81
DP [site] [Sum] [mod] [wsh]
To the site bit, the number of digits is sum, and the remainder of the last digit is mod, And the last digit is wsh
Enumeration 1 ~ 81 is the answer.
Code:
# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "queue" # include "algorithm" # include "iostream" # define EPS 1e-8using namespace STD; // September 23, 2014 10: 06: 20int DP [12] [82] [82] [82], num [12]; int DFS (INT site, int sum, int mod, int wsh, int f) {If (Site = 0) return sum = wsh & mod = 0; If (! F & DP [site] [Sum] [mod] [wsh]! =-1) return DP [site] [Sum] [mod] [wsh]; int Len = f? Num [site]: 9; int ans = 0; For (INT I = 0; I <= Len; I ++) {ans + = DFS (site-1, sum + I, (mod * 10 + I) % wsh, wsh, F & I = Len);} If (! F) DP [site] [Sum] [mod] [wsh] = ans; return ans;} int solve (int x) {int CNT = 0; while (X) {num [++ CNT] = x % 10; X/= 10;} int ans = 0; For (INT I = 1; I <= 82; I ++) {ans + = DFS (CNT, I, 1);} return ans;} int main () {int T, CAS = 1; CIN> T; memset (DP,-1, sizeof (DP); While (t --) {int X, Y; scanf ("% d", & X, & Y ); if (x> Y) Swap (x, y); printf ("case % d: % d \ n", CAS ++, solve (y) -Solve (x-1);} return 0;} // September 23, 2014 10:12:11
[Digital DP] HDU 4389 x Mod f (x)