1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include<bits/stdc++.h> #define mod 1000000007 #define int long long using namespace std; int a[1010],m,f[1010][11][2][2][2],ans1,ans2; inline int DFS(int x,int las,int lasqr,int has,int lim,int st){ if(x<=0) return has; if(~f[x][las][has][lim][st]) return f[x][las][has][lim][st]; int Max=lim?a[x]:9,res=0; for(int i=0;i<=Max;i++) res+=DFS(x-1,i,st?-1:las,has(!st&&i==las)(!st&&i==lasqr),lim&&(i==Max),st&&(i==0))%mod,res%=mod; if(!st&&~lasqr) f[x][las][has][lim][st]=res; return res; } inline int solve(){ if(m<=1) return 0; for(int i=1;i<=m/2;i++) swap(a[i],a[m-i+1]); memset(f,-1,sizeof(f)); return DFS(m,-1,-1,0,1,1); } signed main(){ char ch=getchar();while(ch<'0'ch>'9') ch=getchar(); m=0;while(ch>='0'&&ch<='9') a[++m]=ch-'0',ch=getchar(); a[m]--;int j=m;while(a[j]==-1) a[j-1]--,a[j]+=10,j--; ans1=solve(); while(ch<'0'ch>'9') ch=getchar(); m=0;while(ch>='0'&&ch<='9') a[++m]=ch-'0',ch=getchar(); ans2=solve(); printf("%lld\n",(ans2-ans1+mod)%mod); }
|