Codevs 1137 Calculation factor

Source: Internet
Author: User

Transmission Door

1137 calculation Factor

2011 NOIP National League Improvement Group

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingView Run ResultsTitle Description Description

Given a polynomial (ax + by) ^k, the coefficients of the X^n y^m item are requested after the polynomial is expanded.

Enter a description Input Description

A total of 5 integers, respectively, a,b,k,n,m, separated by a space between each two integers.

Output description Output Description

Output a total of 1 lines, containing an integer, indicating the coefficients, the coefficient may be very large, the output of 10007 modulo results.

Sample input Sample Input

1 1 3) 1 2

Sample output Sample Output

3

Data range and Tips Data Size & Hint

Data range
For 30% of the data, there are 0≤k≤10;
For 50% of data, there is a = 1,b = 1;
For 100% of data, there is 0≤k≤1,000,0≤n, m≤k, and n + M = k,0≤a,b≤1,000,000.

#include <cstdio>#defineM 10007intka[1100][1100]={0};intsum;inta,b,k,n,m;Long LongKsmintYintk) {    Long Longans=1;  while(k>0)      {          if(k%2) ans=ans*y%l; Y=y*y%l; K/=2; }    returnans;}intMain () {scanf ("%d%d%d%d%d",&a,&b,&k,&n,&m); A%=M; b%=M; ka[1][0]=ka[1][1]=1;  for(intI=1; i<=k;i++) ka[i][0]=1;  for(intI=2; i<=k;i++)      for(intj=1; j<=i;j++) Ka[i][j]= (ka[i-1][j-1]+ka[i-1][J])%M; if(a==1&&b==1) printf ("%d", Ka[k][m]); Else{sum= (KSM (a,n) *ksm (b,m))%m*ka[k][m]%l; printf ("%d", sum); }    return 0; }
fast Power + Yang Hui triangle
#include <cstdio>#defineM 10007#defineN 1100intki[n][n]={0};inta,b,k,n,m;intMain () {scanf ("%d%d%d%d%d",&a,&b,&k,&n,&m); A%=l; b%=M; ki[1][0]=A; ki[1][1]=b;  for(intI=2; i<=k;i++)       for(intj=0; j<=i&&j<=m;j++) {Ki[i][j]=ki[i-1][j]*a%l; if(j) Ki[i][j]= (k[i][j]+ki[i-1][j-1]*B)%M; } printf ("%d", Ki[k][m]); return 0;}
Recursive

Codevs 1137 Calculation factor

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.