HDU2089 (Digital DP), hdu2089 digital dp
Question: for the interval [a, B], calculate how many of them do not contain '4' and do not contain '62', 1 <a, B <= 10 ^ 15;
Digital DP Solution. dp [I] [j] indicates the number of I-bits starting with j.
For example, dp [2] [6] represents 60, 61, 66, 69;
Dp [I] [j] = dp [I] [j] + dp [I-1] [k], where 0 <= k <= 9;
# Include <algorithm> # include <iostream> using namespace std; int dp [10] [10]; void init () {dp [0] [0] = 1; // dp [0] [1-9] = 1 can be for (int I = 1; I <= 8; I ++) for (int j = 0; j <10; j ++) // I bit for (int k = 0; k <10; k ++) // I-1 bit if (j! = 4 &&! (J = 6 & k = 2) dp [I] [j] + = dp [I-1] [k];} int solve (int n) {int d [10]; int len = 0; while (n> 0) {d [++ len] = n % 10; n/= 10 ;} d [len + 1] = 0; int ans = 0; for (int I = len; I> = 1; I --) {for (int j = 0; j <d [I]; j ++) {if (j! = 4 &&! (D [I + 1] = 6 & j = 2) ans + = dp [I] [j];} if (d [I] = 4 | (d [I] = 2 & d [I + 1] = 6) break;} return ans ;} int main () {# ifdef xxz // freopen ("in.txt", "r", stdin); # endif // xxz int r, l; init (); while (cin> l> r) {if (r + l = 0) break; cout <solve (r + 1)-solve (l) <endl;} return 0 ;}