题目
第一次了解数位dp,看的这篇博文
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[10][2];
int uplimit[10];int dfs(int pos, int pre, int state, bool limit)
{
if (pos == -1)return 1;if (!limit && dp[pos][state] != -1)return dp[pos][state];int up = limit ? uplimit[pos] : 9;int temp = 0;for (int i = 0; i <= up; i++){
if (pre == 6 && i == 2)continue;if (i == 4)continue;temp += dfs(pos - 1, i, i == 6, limit && i == uplimit[pos]);}if (!limit)dp[pos][state] = temp;return temp;
}int solve(int x)
{
int pos = 0;while (x){
uplimit[pos++] = x % 10;x /= 10;}return dfs(pos - 1, -1, 0, true);
}int main()
{
int le, ri;memset(dp, -1, sizeof(dp));while (cin >> le >> ri && le + ri){
cout << solve(ri) - solve(le - 1) << endl;}system("pause");return 0;
}