codeforces 204A
题意:
题解:
#include <bits\stdc++.h>
using namespace std;
typedef long long ll;
int bit[20];
ll dp[20][10];
ll dfs(int pos, int st, int ed, bool lead, bool limit){
if(pos == 0){
return st == ed;
}
if(!limit && dp[pos][st] != -1){
return dp[pos][st];
}
int up = (limit ? bit[pos] : 9);
ll res = 0;
for(int i = 0 ; i <= up ; i++){
res += dfs(pos-1, (lead == 0) && (i != 0) ? i : st, pos == 1 ? i : ed, lead || i, limit && i == bit[pos]);
}
if(!limit){
dp[pos][st] = res;
}
return res;
}
ll count(ll x){
if(x == 0){
return 1;
}
int len = 0;
while(x){
bit[++len] = x%10;
x /= 10;
}
return dfs(len, 0, -1, false, true);
}
int main() {
memset(dp, -1, sizeof(dp));
ll l, r;
cin >> l >> r;
cout << count(r)-count(l-1) << endl;
return 0;
}