【洛谷P1313】计算系数【数论,数学】

题目大意:

题目链接:https://www.luogu.org/problemnew/show/P1313
(ax+by)k(ax+by)^k展开式中anbma^nb^m项的系数。


思路:

众所周知,(x+y)k(x+y)^k展开式中anbma^nb^m项的系数就是杨辉三角第k+1k+1m+1m+1列的数字。假定为f[n+1][m+1]f[n+1][m+1]
那么很明显,(ax+by)k(ax+by)^k展开式中anbma^nb^m项的系数就是f[n+1][m+1]×anbmf[n+1][m+1] imes a^nb^m
k1000kleq 1000,可以直接用杨辉三角和暴力求幂。


代码:

#include <cstdio>
#include <iostream>
using namespace std;

const int MOD=10007; 
const int N=1010;
int n,m,k,an,s,a,b,C[N][N];

int mul(int x,int M)  //暴力求幂
{
	int y=x;
	while (M--) x=(x*y)%MOD;
	return x;
}

int main()
{
	cin>>a>>b>>k>>n>>m;
	a%=MOD;
	b%=MOD;
	C[1][1]=1;
	for (int i=2;i<N;i++)
		for (int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;  //杨辉三角
	cout<<mul(a,n-1)*mul(b,m-1)%MOD*C[k+1][m+1]%MOD;
	return 0;
} 
原文地址:https://www.cnblogs.com/hello-tomorrow/p/11998401.html