Problem Solving Ideas:
and Hdu 35,551.
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include < algorithm> #include <vector> #include <cmath> #include <queue> #include <stack> #define LL Long long using namespace Std;int dp[10][3];void init () {dp[0][0] = 1;dp[0][1] = dp[0][2] = 0;for (int i=1;i<=6;i++) {dp[i ][0] = dp[i-1][0] * 9-dp[i-1][1];DP [i][1] = dp[i-1][0];DP [i][2] = dp[i-1][0] + dp[i-1][1] + dp[i-1][2] * 10;}} int bit[10];int Solve (int n) {int tmp = N;int len = 0;memset (bit, 0, sizeof (bit)), while (n) {Bit[++len] = n 10;n/= 10;} int ans = 0;bool flag = false;for (int i=len;i>=1;i--) {ans + dp[i-1][2] * BIT[I];IF (flag) ans + = dp[i-1][0] * bit[i];if (!flag && Bit[i] > 4) ans + dp[i-1][0];if (!flag && bit[i+1] = = 6 && bit[i] > 2) ans + = Dp[i ][1];if (!flag && bit[i] > 6) ans + dp[i-1][1];if (bit[i] = = 4 | | (Bit[i+1] = = 6 && bit[i] = = 2)) Flag = true;} if (flag) Ans++;return Tmp-ans;} int main () {init (); INT N, M;while (scanf ("%d%d", &n, &m)!=eof) {if (n = = 0 && m = = 0) break;printf ("%d\n", Solve (m)-solve (n-1));} return 0;}
HDU 2089 do not 62 (digital DP)