容易得到题意转变成
其中
然后根据生成函数的那一套
然后根据等比数列的求和公式变一变形就得到了下面的式子
前面那个二项式展开就可以了,后面学过生成函数就应该知道的
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int maxn = 500000 + 10;
const ll mod = 1000000000 + 7;
ll inv[maxn], fac[maxn], n, m, k;
ll quick(ll a, ll n) {
ll ans = 1;
for (; n; n >>= 1, a = a * a % mod)
if (n & 1) ans = ans * a % mod;
return ans;
}
ll comb(ll n, ll m) {
ll t1 = fac[n], t2 = inv[m];
return t1 * t2 % mod * inv[n - m] % mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
fac[0] = inv[0] = 1;
for (int i = 1; i <= 500000; i++) fac[i] = fac[i - 1] * i % mod;
inv[500000] = quick(fac[500000], mod - 2);
for (int i = 500000 - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
cin >> n >> m >> k;
ll ans = 0;
for (int i = 0; (k + 1) * i <= m; i++) {
ll j = m - (k + 1) * i;
if (i & 1) ans = (ans - comb(n, i) * comb(n + j - 1, n - 1) % mod + mod) % mod;
else ans = (ans + comb(n, i) * comb(n + j - 1, n - 1) % mod) % mod;
}
cout << ans << endl;
return 0;
} 
京公网安备 11010502036488号