样例不过求助,玄关
查看原帖
样例不过求助,玄关
1086062
MoraxNB楼主2024/7/24 14:15

rt

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int N = 1e4 + 10;
int n, dp[20][20], m, num[N], cnt;

int flag(int x, int y) {
    return (x == y ? 1 : 0);
}

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch>'9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int dfs(int d, int len, bool limit, bool zero, int sum) {
    int ans = 0;
    cout << len << ':' << cnt << ':' << sum << endl << endl;
    if (len > cnt) return sum;
    if (len >= 100) return 0;
    //cout << dp[len][sum] << endl;
    if (!limit && !zero && dp[len][sum] != -1) return dp[len][sum];
    int mu = (limit ? num[len] : 9);
    for (int i = 0; i <= mu; i++) {
        ans += dfs(d, len + 1, (i == mu) && limit, !i && zero, sum + ((i == d) && (i || zero)));
    }
    cout << len << ':' << ans << endl;
    if (!limit && !zero) dp[len][sum] = ans;
    return ans;
}

int work(int x, int d) {
    memset(dp, -1, sizeof dp);
    cnt = 0;
    while (x) {
        num[++cnt] = x % 10;
        x /= 10;
    }
    //cout << cnt << endl;
    reverse(num + 1, num + 1 + cnt);
    return dfs(d, 1, 1, 1, 0);
}

signed main() {
    std::ios::sync_with_stdio(false);
    n = read(), m = read();
    for (int i = 0; i <= 9; i++) {
        cout << work(m, i) - work(n - 1, i) << endl;
    }
    return 0;
}

2024/7/24 14:15
加载中...