#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;
int x, y, n, f[100][100];
vector<int> q;
int dfs(int pos, int sta, int done) {
if (pos < 0)
return 1;
if (!done && ~f[pos][sta])
return f[pos][sta];
int res = 0;
int end = done ? q[pos] : 9;
for (int i = sta; i <= end; i++) res += dfs(pos - 1, i, done && i == end);
if (!done)
f[pos][sta] = res;
return res;
}
ll work(int p) {
memset(f, -1, sizeof(f));
q.clear();
while (p > 0) {
q.push_back(p % 10);
p /= 10;
}
n = q.size() - 1;
return dfs(n, 0, 1);
}
int main() {
while (cin >> x >> y) printf("%lld\n", work(y) - work(x - 1));
return 0;
}
#10164. 「一本通 5.3 例 2」数字游戏
最新推荐文章于 2024-08-02 16:23:43 发布