[HDU 2089 not 62] Digital dp

HDU ye still maintain pinching [skull pain] (↓ HDU no access to only take their own questions to the surface)

Description

Hangzhou called those silly sticky man-blah 62 (voice: laoer).
Hangzhou Transportation Authority will expand some of the regular taxi licenses, recently came up with a good news, after the license no longer contains an unlucky number, and this way, you can eliminate the psychological barriers to individual taxi drivers and passengers, and more safely serve the public.
Unlucky all numbers comprising 4 or 62. For example:
623,157,341,888,914
belong to the unlucky number. However, while 61152 contains 6 and 2, but not even the number 62, it does not belong to the unlucky number of columns.
Your task is, for a license plate number each time interval given, infer Authority to pay this time how many cars have to actually give a new taxi vehicle licenses.

Input

Inputs are integers of n, m (0 <n≤m <1000000), if they are integers of 0, the input ends.

Output

For each pair of integers, the output does not contain a statistical number of the unlucky number, the value per line position.

Sample Input

1 100
0 0

Sample Output

80
 
Mentality of QAQ

   Because oj its own test data is relatively weak, so the first time to write hin happily violence before. And other subsequent HDU saw this question, then fine the rain stopped I think the line , then the situation got HDU happily T ...... then happily Baidu, found a happy digit dp
   digit dp, dp counting with one kind, typically used to meet some of the numbers in the statistical number of an interval [l, r] within.
   By definition is the bitwise dp
   so first digital bit ( note hex acridine) dig into the array split out
   this part code is as follows:

while (v) {
    dig [cnt ++] = v% 10; // split from each array into forward
    v / = 10;
  }
 Using dfs then recursion is explained below
    The main part of this code is as follows:
ll dfs (int pos, int six, int flag) {// pos marks the first of several, whether or not a flag before six 6 (if it is 6, six = 1; otherwise, six = 0), whether before the flag tag several upper limit corresponding digits are the same (for example, an upper limit of 1234, three current is 123, flag = 1, the fourth function as told not exceed 4
	if (pos <0) return 1; // return finished bit dfs
	ll ans = 0;
	if (! dp [pos] [six] [flag] = -1) return dp [pos] [six] [flag]; // Memory of 
	for (int i = 0; i <= 9; i++) {
		if (flag == 1 && i > dig[pos]) break;  //判断上限
		if (i == 4) continue; // if the current bit is 4, skip
		if (six && i == 2) continue; // if the former is 6, and the current position is 2, was 62, the number of iterations is skipped
		ans + = dfs (pos - 1, i == 6, flag && i == dig [pos]); // if several topics so far are in line with the requirements, the next will continue dfs, and determines the current number of bits 6 whether, and the upper limit is determined
	}
	return dp [pos] [six] [flag] = ans; // dfs all over it is the answer
}
 
AC Code
. 1 #include <bits / STDC ++ H.>
 2  #define O_O iOS :: sync_with_stdio (to false); cin.tie (0); cout.tie (0);
 . 3  the using  namespace STD;
 . 4 typedef Long  Long LL;
 . 5 LL DP [ 10 ] [ 2 ] [ 2 ];     // DP [bits] [6 before determining whether a] [reaches the current limit bits] 
6  int DIG [ 10 ];
 . 7  
. 8 LL DFS ( int POS, int Six , int In Flag) {
 . 9      IF (POS < 0 ) return  . 1;     // Why do not return 0 (though return 0 0 answer forever is a 
10 LL ANS = 0 ; 11 IF ! (Dp [POS] [Six] [Flag] = - 1 ) return dp [POS] [Six] [In Flag]; // memory of 12 is for ( int I = 0 ; I <= . 9 ; I ++ ) { 13 is IF (In Flag == . 1 && I> DIG [POS]) BREAK ; // Analyzing upper 14 IF (I = = . 4 ) Continue ;   15 IF (I Six && == 2) continue; 16 ans += dfs(pos - 1, i == 6, flag && i == dig[pos]); //递归 17 } 18 return dp[pos][six][flag] = ans; 19 } 20 21 ll solve(ll v) { 22 memset(dp, -1, sizeof(dp)); 23 if (v < 0) return 0; 24 int cnt = 0; 25 while (v) { 26 DIG [CNT ++]% V = 10 ; // split from each array into forward 27 V / = 10 ; 28 } 29 return DFS (CNT - . 1 , 0 , . 1 ); // starting from the highest bit recursive 30 } 31 is 32 int main () { 33 is O_O; 34 is LL n-, m; 35 the while (CIN >> >> n- m) { 36 IF (! && n-m!) BREAK ; 37 [ COUT << Solve (m) - Solve (N- . 1 ) << "\n"; 38 } 39 return 0; 40 }

 

 

Guess you like

Origin www.cnblogs.com/GJnghost/p/11628431.html