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
| #include <cstdio> using namespace std; template <class Type> void read (Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0'; flag && (x = ~x + 1); } template <class Type, class ...rest> void read (Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write (Type x) { x < 0 && (putchar('-'), x = ~x + 1); x > 9 && (write(x / 10), 0); putchar('0' + x % 10); } typedef long long L; const int N = 1e4 + 10, M = 14, mod = 1e9 + 7; void add (int &x, L k) { x = (x + k) % mod; } int n, m, d, f[M][N]; int inv[N], fact[N], ifact[N]; void init () { inv[1] = 1; for (int i = 2; i < N; ++i) inv[i] = (L)(-mod / i) * inv[mod % i] % mod; fact[0] = ifact[0] = 1; for (int i = 1; i < N; ++i) { fact[i] = (L)fact[i - 1] * i % mod; ifact[i] = (L)ifact[i - 1] * inv[i] % mod; } } int C (int a, int b) { return a < b ? 0 : (L)fact[a] * ifact[b] % mod * ifact[a - b] % mod; } int main () { init(); read(n, m, d); f[0][0] = 1; for (int i = 0; i + 1 < M; ++i) for (int j = 0; j <= n - m; ++j) for (int k = 0; j + (k << i) <= n - m; k += d + 1) add(f[i + 1][j + (k << i)], (L)f[i][j] * C(m >> 1, k)); int res = C(n, m); for (int i = 0; i <= n - m; ++i) add(res, -(L)f[M - 1][i] * C(n - i - (m >> 1), m >> 1)); write((res + mod) % mod); return 0; }
|