题意:求区间中不含连续的62和4的数。
题解:数位dp
直接dfs不记忆化也能过。
d
p
[
p
o
s
]
[
s
t
a
]
dp[pos][sta]
dp[pos][sta]:记录当前哪一位,前导是否为6的之后的种数。
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<fstream>
#include<set>
#include<map>
#include<sstream>
#include<iomanip>
#define ll long long
using namespace std;
int n, m, a[6], dp[6][2];
int dfs(int pos, int sta, int limit) {
if (pos == -1) return 1;
if (!limit && dp[pos][sta] != -1) return dp[pos][sta];
int up = limit ? a[pos] : 9;
int ans = 0;
for (int i = 0; i <= up; i++) {
if (sta && i == 2) continue;
if (i == 4) continue;
ans += dfs(pos - 1, i == 6, limit && i == up);
}
if (!limit) dp[pos][sta] = ans;
return ans;
}
int solve(int x) {
int pos = 0;
while (x) {
a[pos++] = x % 10;
x /= 10;
}
return dfs(pos - 1, 0, 1);
}
int main() {
memset(dp, -1, sizeof(dp));
while (~scanf("%d%d", &n, &m) && n) {
printf("%d\n", solve(m) - solve(n - 1));
}
return 0;
}