Problem Description
For a number,if the length of continuous odd digits is even and the length of the continuous even digits are odd,we call it odd -even number. Now we want to know the amount of odd-even number between l,r (1<=l<=r<= 9*10^18).
Inputfirst Line a t,then t cases.every line contains, integers L and R.
Outputprint the output for each case is on one line in the format as shown below.
Test instructions: All consecutive odd-numbered lengths in a number are even, and all consecutive even lengths are odd. We're going to find out how many of these numbers are in a range.
Interval range (1~9*10^18) so it's obviously a digital DP-engage. Set Dp[len][count][temp],temp=1 to mean even, temp=2 for odd, temp=0 to take first 0 o'clock,
Count indicates that there are several odd or even numbers to the Len position. Apparently simple search, standard digital DP
#include <iostream> #include <cstring>using namespace std;typedef long long ll;ll dp[22][22][3];int dig[20]; ll DFS (int len, int count, int temp, int flag, int first) {if (len = = 0) {if (temp = = 1) {if (cou NT% 2 = 0) {return 1; } else {return 0; }} if (temp = = 2) {if (count% 2 = = 0) {return 1; } else {return 0; }} return 0; } if (!flag &&!first && dp[len][count][temp]! =-1) {return dp[len][count][temp]; } int n = flag? Dig[len]: 9; ll sum = 0; for (int i = 0; I <= N; i++) {if (first) {if (i = = 0) {sum + = DFS (len-1, 0, 0, Flag && i = = N, first && i = = 0); } else {if (i% 2 = = 0) {sum + = DFS (len-1, Count + 1, 1, flag &Amp;& i = = N, first && i = = 0); } else {sum + = DFS (len-1, Count + 1, 2, flag && i = = N, First && i = = 0); }}}} else {if (i% 2 = = 0) {if (temp = = 1) {sum + = DFS (len-1, Count + 1, 1, flag && i = = N, first && i = = 0); if (temp = = 2) {if (count% 2 = = 0) {sum + = DFS (len-1, 1, 1 , flag && i = = N, first && i = = 0); }}}} else {if (temp = = 1) {if (count% 2! = 0) { Sum + = DFS (len-1, 1, 2, flag && i = = N, first && i = = 0); }} if (temp = = 2) {sum + = DFS (len-1, Count + 1, 2, flag && i = = N, First && i = = 0); }}}} if (!flag &&!first) {dp[len][count][temp] = sum; } return sum;} ll Get (ll x) {int len = 0; Memset (DP,-1, sizeof (DP)); memset (dig, 0, sizeof (DIG)); if (x = = 0) len = 1; while (x) {Dig[++len] = x 10; x/= 10; } return Dfs (len, 0, 0, 1, 1);} int main () {int t; CIN >> T; int ans = 0; while (t--) {ans++; ll L, R, GG; CIN >> L >> R; cout << "Case #" << ans << ":" << Get (R)-Get (L-1) << Endl; } return 0;}
Hdu 5898 Odd-even number (digital DP)