P1739计算系数
描述
给定一个多项式(ax + by)^k,请求出多项式展开后x^n * y^m项的系数。
格式
输入格式
共一行,包含5个整数,分别为a,b,k,n,m,每两个整数之间用一个空格隔开。
输出格式
输出共1行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007取模后的结果。
限制
1s
提示
对于30%的数据,有0 ≤ k ≤ 10;
对于50%的数据,有a = 1, b = 1;
对于100%的数据,有0 ≤ k ≤ 1000,0 ≤ n, m ≤ k,且n+m = k,0 ≤ a,b ≤ 1,000,000.
来源
NOIp2011提高组Day2第一题
系数满足杨辉三角,a的幂次与x相同,b的幂次与y相同。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define N 2003
#define p 10007
#define LL long long
using namespace std;
int a,b,k,n,m;
LL c[N][N];
void solve(int n)
{
for (int i=1;i<=n;i++) c[i][0]=1;
for (int i=1;i<=n;i++)
for (int j=1;j<=i;j++)
c[j][i]=(c[j][i-1]+c[j-1][i-1])%p;
}
LL quickpow(LL num,int x)
{
LL base=num%p; LL ans=1;
while (x)
{
if (x&1) ans=ans*base%p;
base=(base*base)%p;
x>>=1;
}
return ans;
}
int main()
{
scanf("%d%d%d%d%d",&a,&b,&k,&n,&m);
solve(k*2);
LL t=quickpow((LL)a,n);
LL t1=quickpow((LL)b,m);
printf("%I64d\n",(t*t1%p*c[n+1][k+1])%p);
}