【数位DP】Codeforces 1036C Classy Numbers

Just wanted to see if the board can not be set too ......

The results can

 1 #include <bits/stdc++.h>
 2 #define inf 0x3f3f3f3f
 3 #define For(i,a,b) for(int i=a;i<=b;++i)
 4 #define Dec(i,b,a) for(int i=b;i>=a;--i)
 5 #define file() freopen("c:/users/asus/desktop/v.txt","r",stdin)
 6 using namespace std;
 7 
 8 typedef long long ll;
 9 inline ll qr(){
10     ll x=0,f=1; char ch;
11     while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
12     for(;isdigit(ch);x=x*10+ch-48,ch=getchar());
13     return x*f;
14 }
15 ll d[20][11][4];
16 int a[20];
17 ll dfs(int p,int pre,int w,bool lim)
18 {
19     if(p==0) return w<=3;
20     if(w>3) return 0;
21     if(!lim && ~d[p][pre][w]) return d[p][pre][w];
22     int mx = lim ? a[p] : 9;
23     ll s=0;
24     For(i,0,mx) s += dfs(p-1,i,w+(i>0),lim&&i==mx);
25     if(!lim) d[p][pre][w]=s;
26     return s;
27 }
28 ll solve(ll n)
29 {
30     int len=0;
31     while(n) a[++len]=n%10,n/=10;
32     memset(d,-1,sizeof d);
33     return dfs(len,10,0,1);
34 }
35 int main()
36 {
37     // file();
38     ll n=qr(),l,r;
39     For(i,1,n) l=qr(),r=qr(), printf("%lld\n", solve(r)-solve(l-1));
40     return 0;
41 }
View Code

 

Guess you like

Origin www.cnblogs.com/uuuxxllj/p/10954761.html