题目传送门
数位dp,没啥好说的
#include<iostream> #include<cstdio> #include<cstring> #define mod 1000000007 using namespace std; int t,s[20],len; long long l,r,ans,ans1,f[20][2][15]; inline void fenjie(long long x) { len = 0; while(x) { s[++len] = x % 10; x /= 10; } } inline long long dfs(int d,int sum,bool li,int p) { if(d == 0) return sum % mod; if(f[d][li][p] != -1) return f[d][li][p]; long long ss = 0; int res = li ? s[d] : 9; for(int i = 0;i <= res; i++) ss = (ss + dfs(d - 1,sum + (i == p),li && (i == res),p) % mod) % mod; f[d][li][p] = ss % mod; return ss % mod; } inline void chushihua() { ans = ans1 = 0; len = 0; memset(f,-1,sizeof(f)); memset(s,0,sizeof(s)); } int main() { scanf("%d",&t); while(t--) { scanf("%lld%lld",&l,&r); chushihua(); fenjie(l - 1); for(int i = 1;i <= 9; i++) { memset(f,-1,sizeof(f)); ans = (ans + (dfs(len,0,1,i) % mod * i) % mod) % mod; } fenjie(r); for(int i = 1;i <= 9; i++) { memset(f,-1,sizeof(f)); ans1 = (ans1 + (dfs(len,0,1,i) % mod * i) % mod) % mod; } printf("%d ",(ans1 - ans + mod) % mod); } return 0; }