递推数位dp虽然AC了但是没过样例
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
static int dp[15][15][2][2];
int calc(int num, int d)
{
if (num == 0) if (d == 0) return 1;
if (num == 0) return 0;
memset(dp, 0, sizeof(dp));
dp[0][0][1][0] = 1;
std::string s = std::to_string(num);
int n = s.size();
for (int pos = 0; pos < n; pos++)
{
for (int cnt = 0; cnt <= pos; cnt++)
{
for (int tight = 0; tight <= 1; tight++)
{
for (int leadingZero = 0; leadingZero <= 1; leadingZero++)
{
int up = tight ? s[pos] - '0' : 9;
for (int digit = 0; digit <= up; digit++)
{
int newTight = tight && (digit == up);
int newLeadingZero = leadingZero;
int newCnt = cnt;
if (leadingZero == 0 && digit != 0)
{
newLeadingZero = 1;
}
if (newLeadingZero && digit == d)
{
newCnt++;
}
dp[pos + 1][newCnt][newTight][newLeadingZero] += dp[pos][cnt][tight][leadingZero];
}
}
}
}
}
int res = 0;
for (int cnt = 0; cnt <= n; cnt++)
{
for (int tight = 0; tight <= 1; tight++)
{
for (int leadingZero = 0; leadingZero <= 1; leadingZero++)
{
res += dp[n][cnt][tight][leadingZero] * cnt;
}
}
}
return res;
}
void solve()
{
int a, b;
std::cin >> a >> b;
if (a > b) std::swap(a, b);
std::vector<int> counts(10, 0);
for (int d = 0; d < 10; d++)
{
counts[d] = calc(b, d) - calc(a - 1, d);
}
for (int d = 0; d < 10; d++)
{
std::cout << counts[d] << (d == 9 ? '\n' : ' ');
}
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr); std::cout.tie(nullptr);
solve();
return 0;
}