https://cn.vjudge.net/contest/312853#problem/G
Let's call some positive integer classy if its decimal representation contains no more than 33 non-zero digits. For example, numbers 44, 200000200000, 1020310203 are classy and numbers 42314231, 102306102306, 72774200007277420000 are not.
You are given a segment [L;R][L;R]. Count the number of classy integers xx such that L≤x≤RL≤x≤R.
Each testcase contains several segments, for each of them you are required to solve the problem separately.
Input
The first line contains a single integer TT (1≤T≤1041≤T≤104) — the number of segments in a testcase.
Each of the next TT lines contains two integers LiLi and RiRi (1≤Li≤Ri≤10181≤Li≤Ri≤1018).
Output
Print TT lines — the ii-th line should contain the number of classy integers on a segment [Li;Ri][Li;Ri].
Example
Input
4 1 1000 1024 1024 65536 65536 999999 1000001
Output
1000 1 0 2
题意:如果一个数的十进制表示没有超过3个非零的数的话就称之为classy数,现在给你区间a,b求之间有多少个这样的数
裸的数位dp,sta表示非零数的个数就ok了
#include<bits/stdc++.h>
//#include<cstdio>
//#include<algorithm>
//#include<cstring>
//#include<map>
//#include<iostream>
#pragma GCC optimize(3)
#define max(a,b) a>b?a:b
using namespace std;
typedef long long ll;
ll dp[25][25];
int a[25];
ll dfs(int pos,int sta,bool limit){
if(pos==0) return sta<=3;
if(!limit&&dp[pos][sta]!=-1) return dp[pos][sta];
int up=limit?a[pos]:9;
ll ans=0;
for(int i=0;i<=up;i++){
if(i) ans+=dfs(pos-1,sta+1,limit&&i==up);
else ans+=dfs(pos-1,sta,limit&&i==up);
}
if(!limit) dp[pos][sta]=ans;
return ans;
}
ll solve(ll x){
int pos=0;
while(x){
a[++pos]=x%10;
x/=10;
}
return dfs(pos,0,true);
}
int main(){
ios::sync_with_stdio(false);
cout.tie(NULL);
int T;
scanf("%d",&T);
memset(dp,-1,sizeof(dp));
while(T--){
ll a,b;
scanf("%I64d%I64d",&a,&b);
printf("%I64d\n",solve(b)-solve(a-1));
}
return 0;
}