这个论文里面的思想大概都是用多叉树来实现的数位DP...
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
long long l,r,m;
int cntl,cntr,nol[18+5],nor[18+5];
struct M{
long long x,y;
M(long long a=0,long long b=0){
x=a,y=b;
}
inline void init(void){
x=-1,y=0;
}
friend M operator + (M a,M b){
M res;
res.x=a.x+b.x;
res.y=b.y;
return res;
}
}f[19][201][1001];
inline M dfs(int dep,long long sum,long long rem,bool lf,bool rf){
if(!dep)
return sum+rem>=m?M(1,0):M(0,sum+rem);
if(!lf&&!rf&&f[dep][sum][rem].x!=-1)
return f[dep][sum][rem];
M ans=M(0,rem);
for(int i=(lf?nol[dep]:0);i<=(rf?nor[dep]:9);i++)
ans=ans+dfs(dep-1,sum+i,ans.y,lf&&i==nol[dep],rf&&i==nor[dep]);
if(!lf&&!rf)
f[dep][sum][rem]=ans;
return ans;
}
signed main(void){
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
scanf("%lld%lld%lld",&l,&r,&m);
while(l) nol[++cntl]=l%10,l/=10;
while(r) nor[++cntr]=r%10,r/=10;
for(int i=0;i<=18;i++)
for(int j=0;j<=200;j++)
for(int k=0;k<=1000;k++)
f[i][j][k].init();
printf("%lld\n",dfs(cntr,0,0,1,1).x);
return 0;
}