Bnut 1581 233333333 digit DP
To find the funny numbers between N and M, the numbers that contain 23 or 5 are funny numbers, a bare digital DP.
DP[I][J][K] Dp[i][j][k] is the number of funny numbers (k=1) (k=1), not the number of funny numbers (k=0), which is J at the highest level of the I-digit.
Code:
/************************************************************************* > File name:e.cpp > Author:gwq > mail:gwq5210@qq.com > Created time:2015 May 01 Friday 14:30 36 Seconds ***************************************** /#include <cmath> #include <ctime> #include <cctype> #include < climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <map> #include < set> #include <queue> #include <stack> #include <string> #include <vector> #include < sstream> #include <iostream> #include <algorithm> #define INF (INT_MAX/10) #define CLR (arr, Val) memset (
Arr, Val, sizeof (arr)) #define PB push_back #define SZ (a) ((int) (a). Size ()) using namespace Std;
typedef set<int> SI;
typedef vector<int> VI;
typedef map<int, Int> Mii;
typedef long Long LL;
Const double ESP = 1e-5;
#define N-int dp[n][n][2], ans[n]; int gEtans (int n) {int ans = 0;
Char S[n];
sprintf (S, "%d", n);
int len = strlen (s);
int flag = 0;
for (int i = 0; i < len; ++i) {int x = s[i]-' 0 ';
for (int j = 0; j < x; ++j) {ans + = dp[len-i][j][1]; if (flag | | (I! = 0 && J = = 3 && s[i-1] = = ' 2 ') | |
j = = 5) {ans + = dp[len-i][j][0];
}//printf ("%d%d%d%d\n", Len-i, J, Dp[len-i][j][0], dp[len-i][j][1]);
}//printf ("\ n"); if (s[i] = = ' 5 ' | | (S[i] = = ' 3 ' && s[i-1] = = ' 2 '))
{flag = 1;
}} return ans;
} int main (int argc, char *argv[]) {CLR (DP, 0);
DP[1][5][1] = 1;
Dp[1][0][0] = 1;
Dp[1][1][0] = 1;
Dp[1][2][0] = 1;
Dp[1][3][0] = 1;
Dp[1][4][0] = 1;
Dp[1][6][0] = 1;
Dp[1][7][0] = 1;
Dp[1][8][0] = 1;
Dp[1][9][0] = 1;
for (int i = 2, i < N; ++i) {for (int j = 0; J < ++j) { for (int k = 0, K < 2; ++k) {for (int l = 0; l < ++l) {if (k = = 0) {if (J! = 5 && (J! = 2 | | L! = 3)) {Dp[i][j][k] + = Dp[i
-1][L][0];
}} else {dp[i][j][k] + = dp[i-1][l][1];
if ((j = = 2 && L = = 3) | | j = 5) {Dp[i][j][k] + = dp[i-1][l][0];
}}}}}} int n, m;
while (scanf ("%d%d", &n, &m)! = EOF) {if (n = = 0 && m = = 0) {break;
} int a = Getans (M + 1);
int b = Getans (n);
printf ("%d%d%d\n", A, B, a-a);
printf ("%d\n", A-B);
} return 0; }