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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <algorithm>
#include <cstdio>
#include <functional>
#include <map>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define VAR(v,w) __typeof(w) v=(w)
#define ALL(c) (c).begin(),(c).end()
#define SD second
#define INT(x) int x; scanf("%d", &x)

typedef long long LL;
typedef vector<int> VI;

const int mod = 1000000007;
int k, revk;
map<VI, int> cache;

inline LL MODL(LL a,LL b) {
	return a >= 0 ? a % b : b + ((a + 1) % b) - 1;
}

LL EXTEUC(LL a, LL b, LL& x, LL& y) {
	x = 1;
	y = 0;
	LL x1 = 0, y1 = 1;
	while (b != 0) {
		LL t = b;
		LL q = a / b;
		b = a % b;
		a = t;
		t = x1;
		x1 = x - q * x1;
		x = t;
		t = y1;
		y1 = y - q * y1;
		y = t;
	}
	return a;
}

LL REVM(LL a, LL m) {
	LL x, y;
	EXTEUC(m, a, x, y);
	return MODL(y, m);
}

int go(const VI& v) {
	VAR(it,cache.find(v));
	if (it != cache.end()) return it->SD;
	int r = 0;
	FOR(d,1,k+1) {
		VI w(v);
		if (w[0] <= d) break;
		w[0] -= d;
		sort(ALL(w), greater<int>());
		r = (r + go(w)) % mod;
	}
	r = LL(r) * revk % mod;
	r = (r + 1) % mod;
	cache[v] = r;
	return r;
}

int main() {
	INT(n);
	INT(k1);
	INT(m);
	k = k1;
	revk = REVM(k, mod);
	printf("%d\n", go(VI(n, m)));
}