做一下数位DP专题... 估计最后只能写一半
(提高)『数位DP』从入门到入土
P4999 烦人的数学作业
板子题
点击查看代码
int num[20];
ll f[20][200];
ll dfs(int pos, bool limit , ll sum){
if(pos == 0) return sum;
if(!limit && f[pos][sum] != -1) return f[pos][sum];
int len = limit ? num[pos] : 9;
ll ans = 0;
for(int i = 0; i <= len; i ++){
ans = (ans + dfs(pos - 1, limit && i == len, sum + i)) % mod;
}
if(!limit) f[pos][sum] = ans;
return ans;
}
ll calculate(ll x){
int pos = 0;
while (x){
num[++pos] = x % 10;
x /= 10;
}
return dfs(pos,1 , 0);
}
void solve(){
ll L, R;
cin >> L >> R;
cout << (calculate(R) - calculate(L - 1) + mod) % mod << endl;
}
int main(){
memset(f, -1, sizeof f);
int t;
cin >> t;
while (t --) solve();
return 0;
}