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
#include <bits/stdc++.h>
using namespace std;

const int mod = 1'000'000'007;

int qpow(int a, int b) {
    int res = 1;
    for (; b; b /= 2) {
        if (b % 2) {
            res = (int64_t)res * a % mod;
        }
        a = (int64_t)a * a % mod;
    }
    return res;
}

map<vector<int>, int> M;
int solve(vector<int> scores, int k, int inv_k, int m) {
    ranges::sort(scores);
    if (ranges::max(scores) >= m) {
        return 0;
    }
    if (M.contains(scores)) {
        return M[scores];
    }

    int res = 0;
    for (int x = 1; x <= k; ++x) {
        scores[0] += x;
        res = (res + (int64_t)(1 + solve(scores, k, inv_k, m)) * inv_k) % mod;
        scores[0] -= x;
    }
    return M[scores] = res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, m;
    cin >> n >> k >> m;
    int inv_k = qpow(k, mod - 2);
    vector scores(n, 0);
    cout << solve(scores, k, inv_k, m) << '\n';
    return 0;
}