数位DP还是挺简单的。。。预处理a[i][j][k]即有i个数最高位为j,k的个数,数据规模小乱搞就行。。

为什么交了freopen都AC_(:зゝ∠)_

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 1e9
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define NM 20
10 using namespace std;
11 ll read(){
12     ll x=0,f=1;char ch=getchar();
13     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
14     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
15     return x*f;
16 }
17 ll a[NM][NM][NM],b[NM],c[NM],A[NM],B[NM],s[NM],n,m,p=14;
18 void dp(ll x){
19     mem(s);mem(b);ll v=x;
20     inc(i,1,p)b[i]=x%10,x/=10;
21     ll t=p;x=v;
22     while(!b[t])t--;
23     inc(i,1,t-1)
24     inc(j,1,9)
25     inc(k,0,9)s[k]+=a[i][j][k];
26     inc(j,1,b[t]-1)
27     inc(k,0,9)s[k]+=a[t][j][k];
28     s[b[t]]+=x%c[t];
29     dec(i,t-1,1){
30         inc(j,0,b[i]-1)
31         inc(k,0,9)s[k]+=a[i][j][k];
32         s[b[i]]+=x%c[i];
33     }
34 }
35 int main(){
36 //    freopen("data.in","r",stdin);
37     n=read();m=read();
38     c[1]=1;
39     inc(i,2,p)c[i]=c[i-1]*10;
40     inc(i,0,9)a[1][i][i]=1;
41     inc(i,2,p)
42     inc(j,0,9){
43         inc(k,0,9)
44         inc(v,0,9)
45         a[i][j][v]+=a[i-1][k][v];
46         a[i][j][j]+=c[i];
47 //        inc(k,0,9)printf("%lld ",a[i][j][k]);printf("\n");
48     }
49     dp(n);
50     inc(i,0,9)A[i]=s[i];
51     dp(m+1);
52     inc(i,0,9)B[i]=s[i];
53     inc(i,0,9)if(i==9)printf("%lld\n",B[i]-A[i]);else printf("%lld ",B[i]-A[i]);
54     return 0;
55 }
View Code

 

posted on 2016-01-13 19:54  onlyRP  阅读(158)  评论(0编辑  收藏  举报