注意以下几点:
搜索维度非约束条件的都要记录,否则大概率出错,比如_0
st参数传递和_0的互相影响要分辨清楚
num==-1就要返回0而不是1
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 30;
const int MOD = 2520;
const double eps = 1e-10;
typedef long long ll;
const int oo = 0x3f3f3f3f;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll a[maxn],dp[maxn][maxn];
ll DP(int cur,int limit,int _0,int st){
if(cur==0&&st) return 1;
if(cur==0) return _0;
if(dp[cur][_0]!=-1&&!limit&&!st) return dp[cur][_0];
int up=limit?a[cur]:9;
ll ans=0;
rep(i,0,up){
ans+=DP(cur-1,limit&&a[cur]==i,(st&&i==0)?0:_0+(i==0),st&&(i==0));
}
return (limit||st)?ans:dp[cur][_0]=ans;
}
ll solve(ll num){
if(num==-1)return 0;
if(num==0) return 1;
int cur=0;
while(num){
a[++cur]=num%10;
num/=10;
}
return DP(cur,1,0,1);
}
int main(){
memset(dp,-1,sizeof dp);
int T=read(),kase=0;
while(T--){
ll l=read();
ll r=read();
printf("Case %d: ",++kase);
println(solve(r)-solve(l-1));
}
return 0;
}