Description
Recently, CEN is very popular with digital games. A person is named a number that is equal to or greater than 123,446. Now, you decide to play a game by specifying an integer closed interval [a, B] [a, B] [a, B] And asking how many of them do not fall.
A digital DP template. The enumeration starts from the current status when the memory is searched. For more information, see annotations.
# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <cmath> # include <cstdlib> # include <queue> # include <stack> # include <vector> using namespace STD; # define maxn 100010 # define INF 10000009 # define mod 10000007 # define ll long # define in (a) a = read () # define rep (I, k, n) for (INT I = K; I <= N; I ++) # define drep (I, k, n) for (INT I = K; I> = N; I --) # define Cl (a) memset (A, 0, sizeof (A) inline Int read () {int x = 0, F = 1; char CH = getchar (); (;! Isdigit (CH); CH = getchar () if (CH = '-') F =-1; for (; isdigit (CH); CH = getchar ()) X = x * 10 + CH-'0'; return x * F;} inline void out (int x) {If (x <0) putchar ('-'), X =-X; If (x> 9) Out (X/10); putchar (X % 10 + '0');} int N, f [12] [12], digit [12]; ll DFS (INT POs, int U, int flag) {// POS indicates the current bit, and u indicates the current state, flag determines whether to cross-border if (Pos = 0) return 1; // If the enumeration is complete, this is a case where ll ans = 0; int end; If (FLAG) end = digit [POS]; // if the number of the current enumeration exceeded, that is, the edge is wiped, then the maximum else end is 9; // if the current edge is not wiped, so long casually enumerate rep (I, U, end) ans + = DFS (pos-1, I, flag & I = end); Return ans;} ll get (int K) {int L = 0; while (k) {digit [++ L] = K % 10; k/= 10;} DFS (L, 0, 1);} int main () {int A, B; while (CIN> A> B) cout <get (B)-Get (A-1) <Endl; return 0 ;}
Loj10164 digital Game 1