Hdu 5201 the Monkey King function Taylor unfold
Test instructions
There are n apples, m individuals, asked to give the first person the most, others arbitrarily, ask how many kinds of division. Final result modulo 1000000007.
Limit:
1 <= n,m <= 100000
Ideas:
Female function, Taylor unfold
Enumerate the apples of the first person, set to u,
The remaining apples are n-u, divided into m-1 parts:
The Build function is:
G (x) = (1+x+x^2+...+x^ (u-1)) ^ (m-1)
= G (x) = ((1-x^u)/(1-x) ^ (m-1)
= G (x) = (1-x^u) ^ (m-1)/(1-x) ^ (m-1)
= G (x) = (1-x^u) ^ (m-1) * (1-x) ^ (1-m) ---one-piece
For any two-item type, its Taylor expansion is:
(1+x) ^k = 1 + kx + K (k-1)/2!*x^2 + ... + k (k-1) ... (k-n+1)/n!x^k + ...
For the "One" Taylor expansion, get two polynomial multiplication, and for each u, you can find the "one" x^ (n-u) coefficients, the results.
/*hdu 5201 The Monkey King test instructions: There are n apples, m individuals, asked to give the first person the most, others arbitrarily, ask how many kinds of division. Final result modulo 1000000007. Limit: 1 <= n,m <= 100000 ideas: Female function, Taylor Expand enumeration The first person to the apple, set to U, the remaining apples for n-u, divided into m-1 parts, then there: the generating function is: G (x) = (1+x+x^2+...+x^ (u-1)) ^ (m-1) = g (x) = ((1-x^u)/(1-x)) ^ (m-1) = g (x) = (1-x^u) ^ (m-1)/(1-x) ^ (m-1) = g (x) = (1-x^u) ^ (m-1) * (1-x) ^ (1-M)--- For any two-item type, its Taylor expansion is: (1+x) ^k = 1 + kx + K (k-1)/2!*x^2 + ... + k (k-1) ... (k-n+1)/n!x^k + ... For the "One" Taylor expansion, get two polynomial multiplication, and for each u, you can find the "one" x^ (n-u) coefficients, the results. */#include <iostream> #include <cstdio>using namespace std; #define LL __int64const int Mod=1000000007;const int n=1000005; LL INV (ll A,ll m) {ll p=1,q=0,b=m,c,d;while (b>0) {c=a/b;d=a; a=b; b=d%b;d=p; p=q; q=d-c*q;} return p<0?p+m:p;} LL fac[n],ny[n];void Predo () {FAC[0]=1;NY[0]=INV (fac[0],mod); for (int i=1;i<n;++i) {fac[i]=fac[i-1]*i%mod;ny[i]= INV (FAC[I],MOD);}} LL C (int n,int m) {if (m<0 | | n<m) return 0;return fac[n]*ny[m]%mod*ny[n-m]%mod; int main () {int t;int n,m;predo (); scanf ("%d", &t); while (t-) {scanf ("%d%d", &n,&m), if (m==1) {puts ("1"); Continue }ll ans=0;for (int i=1;i<=n;++i) {LL fu=1;for (int j=0;j*i<=n-i && j<m;++j) {ans= (Ans+c, N-i-j*i) *c (m-1,j) *fu%mod+mod)%mod;fu=-fu;}} printf ("%i64d\n", ans);} return 0;}
Hdu 5201 the Monkey King function Taylor unfold