Given X and Y, the number of even digits between [x, y] is equal to or equal to one minus odd digits.
One digit is the first.
Example: 10 = 1-0 = 1 so 10 is such a number
Idea: digit DP [I] [Sum] [OK] I bit and sum whether there is a leading 0.
Then, because there is a negative number, 0 is set to 100 Based on the range, and then the last and equal to 101 are the numbers.
Code:
[CPP]View plaincopyprint?
- # Include "cstdlib"
- # Include "cstdio"
- # Include "cstring"
- # Include "cmath"
- # Include "stack"
- # Include "algorithm"
- # Include "iostream"
- Using namespace STD;
- Int DP [12] [200] [2], num [12];
- Int fuck [2] = {1,-1 };
- Int DFS (INT site, int sum, int OK, int F)
- {
- If (Site = 0)
- {
- If (OK = 0) return 0;
- Return sum = 101? 1:0; // The sum of small processing and 101
- }
- If (! F & DP [site] [Sum] [OK]! =-1) return DP [site] [Sum] [OK];
- Int Len = f? Num [site]: 9;
- Int ans = 0;
- For (INT I = 0; I <= Len; I ++)
- {
- If (OK = 0)
- {
- If (I = 0) ans + = DFS (site-1, sum, OK | I! = 0, F & I = Len );
- Else ans + = DFS (site-1, sum + I * fuck [Site % 2], OK | I! = 0, F & I = Len );
- }
- Else
- {
- Ans + = DFS (site-1, sum + I * fuck [Site % 2], OK | I! = 0, F & I = Len );
- }
- }
- If (! F) DP [site] [Sum] [OK] = ans;
- Return ans;
- }
- Int solve (int x)
- {
- If (x <0) return 0;
- Int CNT = 0;
- While (X)
- {
- Num [++ CNT] = x % 10;
- X/= 10;
- }
- Return DFS (CNT, 100, 0, 1); // sum =
- }
- Int main ()
- {
- Int T;
- Scanf ("% d", & T );
- Memset (DP,-1, sizeof (DP ));
- While (t --)
- {
- Int X, Y;
- Scanf ("% d", & X, & Y );
- Printf ("% d \ n", solve (y)-solve (x-1 ));
- }
- Return 0;
- }
[Digital DP] spoj 10738 ra-one numbers