Codevs 1137 Calculation Factor 2011 NOIP National League Improvement Group

Source: Internet
Author: User
Tags time limit

1137 Calculation factor 2011 NOIP National League Increase group
time limit: 1 s
Space limit: 128000 KB
Title level: Gold Gold
Title Description Descripti On
Given a polynomial (ax + by) ^k, the coefficients of x^n y^m items are requested after the expansion of the polynomial. The
Input description input Description
contains a total of 5 integers, each of which is a,b,k,n,m, separated by a space between each of the two integers. The
Output description output Description
Outputs a total of 1 rows, containing an integer representing the coefficients to be obtained, which may be large, and the output will result in 10007 modulo.
Sample Input Sample inputs
1 1 3 1 2
Sample outputs sample output
3
data range and hints Data Size & Hint
Data range
for 3 0% of the data, there are 0≤k≤10;
for 50% of the data, there is a = 1,b = 1;
for 100% of the data, there is 0≤k≤1,000,0≤n, m≤k, and n + M = k,0≤a,b≤1,000,000.
Category Tags Tags
continental Noip National League increase 2011

/* Yang Hui triangle + fast power. In fact, you can push it yourself. And then what bothers me is that the problem can be directly with a and b when the initial factor runs the Yang Hui Triangle. Oh, ah, the brain is low. */#include <iostream> #include <cstdio> #define MAXN 1010 #define MOD 10007 #define LL long Long using NAMESPAC
e std;
int F[MAXN][MAXN];
int a1,b1,k,m,n;
int ans;
    ll mi (ll A,ll b) {ll tot=1;
        while (b) {if (b&1) tot= (tot*a)%mod;
        A= (a*a)%mod;
    b>>=1;
} return tot;
    } void Slove () {for (int i=1;i<=k;i++) f[i][1]=f[i][i+1]=1;
        for (int i=2;i<=k;i++) for (int j=2;j<=i;j++) {f[i][j]= (f[i-1][j]+f[i-1][j-1])%mod;
    } Ans=f[k][k-n+1]%mod;
    if (n) ans= (Ans*mi (a1%mod,n))%mod;
    if (m) ans= (Ans*mi (b1%mod,m))%mod;
printf ("%d", ans%mod);
    } int main () {scanf ("%d", &A1);cin>>b1>>k>>n>>m;
    Slove ();
return 0; }

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.