Hdu 5201 the Monkey King function Taylor unfold

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.