Description:
\(1<=n,k<=1e5,mod~1e9+7\)
answer:
DP considered most classic arrangement, each inserted into the first \ (I \) a large number, it can increase the number of reverse is \ (I--0. 1 \) .
Generating function is easy to get:
\(Ans=\prod_{i=0}^{n-1}(\sum_{j=0}^ix^j)[x^k]\)
\(=\prod_{i=1}^{n}{1-x^i\over 1-x}[x^k]\)
The denominator is a classic of the generating function:
\({1\over 1-x}^n=(\sum_{i>=0}x^i)^n=\sum_{i>=0}C_{i+n-1}^{n-1}\)
The question then becomes of the requirements:
\ (\ prod_ {i = 1 } ^ {n} {1-x ^ i} \) the first k entries.
DP consider using integer division, corresponding to the different and are divided into a number k <= n and the number of coefficients is \ ((--1)} ^ {counted number \) .
Not difficult to come dp:
Set \ (F [i] [j] \) represents the number i has been divided, and for all programs and j coefficients.
转移\(f[i][j]=f[i][j-i]-f[i-1][j-i]+f[i-1][j-(n+1)]\)
Because of \ (I <= \ sqrt {2K} \) , so complexity is \ (O (K \ sqrt K) \) .
Another polynomial exp approach:
Ln this equation might be the last re-exp back.
We know that:
\ (LN (1 + x) \)
$=\int ~ln(1+x)' $
\(=\int~{1\over 1+x}\)
\(=\int ~ \sum_{i>=0}(-1)^ix^i\)
\(=\sum_{i>=1}{(-1)^{i-1}x^i\over i}\)
\(Ans=exp(\sum_{i=1}^n(ln(1-x^i)-ln(1-x)))[x^k]\)
\(ln(1-x^i)=\sum_{j>=1}{(-1)^{(j-1)i}x^{ij} \over j}\)
So violence unfold only harmonic series of useful items.
\ (ln (1-x) \) after violence launched empathy can be multiplied by n.
Complexity \ (O (the n-~ ~ the n-log) \) , but to write MTT, so run giant slow, and difficult to write.
Code:
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i < B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;
const int mo = 1e9 + 7;
ll ksm(ll x, ll y) {
ll s = 1;
for(; y; y /= 2, x = x * x % mo)
if(y & 1) s = s * x % mo;
return s;
}
const int N = 1e5 + 5;
int n, k, m;
ll fac[N * 2], nf[N * 2];
ll f[450][N];
ll g[N];
void calc(int n) {
fac[0] = 1; fo(i, 1, n) fac[i] = fac[i - 1] * i % mo;
nf[n] = ksm(fac[n], mo - 2); fd(i, n, 1) nf[i - 1] = nf[i] * i % mo;
}
ll C(int n, int m) {
return fac[n] * nf[n - m] % mo * nf[m] % mo;
}
int main() {
freopen("b.in", "r", stdin);
freopen("b.out", "w", stdout);
calc(200000);
scanf("%d %d", &n, &k);
m = sqrt(2 * k);
f[0][0] = 1;
fo(i, 1, m) {
fo(j, i, k) {
f[i][j] = f[i][j - i] - f[i - 1][j - i];
if(j >= n + 1) f[i][j] += f[i - 1][j - (n + 1)];
f[i][j] %= mo;
}
}
ll ans = 0;
fo(i, 0, k) {
fo(j, 0, m) g[i] += f[j][i];
g[i] %= mo;
ans += g[i] * fac[n - 1 + (k - i)] % mo * nf[k - i] % mo;
}
ans = (ans % mo * nf[n - 1] % mo + mo) % mo;
pp("%lld\n", ans);
}