1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include<bits/stdc++.h>
using namespace std;
const int N = 15;
int l,r,len,a[N],dp[N][N];
int dfs(int pos,int sum,int num,int lead,int limit) {
if(pos==0) {
//0位数字
if(lead && !num) return 1;
return sum;
}
if(not limit && not lead && dp[pos][sum] != -1) {
//有几个位可以填 0
return dp[pos][sum];
}
// 无限制,并且无前导0
int res = 0,up = limit? a[pos]:9;
for (int i=0;i<=up;i++) {
int t = 0;
if (i == num) {
if(num == 0) {
//
t = sum + (not lead);
}else {
t = sum+1;
}
}else {
t = sum;
}
res += dfs(pos-1,t,num,lead && i == 0, limit && i == up);
}
if (limit || lead) {
return res;
}
dp[pos][sum] = res;
return res;
}
int count(int x,int u) {
memset(dp,-1,sizeof dp);
len = 0;
while(x) a[++len] = x%10,x/=10;
return dfs(len,0,u,1,1);
}
int main()
{
while(cin>>l>>r ,l || r) {
if (l>r) swap(l,r) ;
for (int i=0;i<=9;i++)
cout << count(r,i) - count(l-1,i) << " ";
cout << endl;
}
return 0;
}
|