Luogu P1313 计算系数

Description:

给定一个多项式(by+ax)^k ,请求出多项式展开后x^n * y^m 项的系数

Analysis:

[C_k^m imes a^n imes b^m ]

Code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int mod = 10007;
typedef long long ll;
ll Pow(ll a,ll b)
{
	ll c = 1;
	for(;b;b >>= 1)
	{
		if(b&1)
		{
			c = a*c%mod;
		}
		a = a*a%mod;
	}
	return c%mod;
}
ll tri[1011][1011],a,b,k,n,m;
int main()
{
	scanf("%d%d%d%d%d",&a,&b,&k,&n,&m);
	tri[1][1] = 1;
	for(int i = 2;i <= k + 1;++i)
	{
		for(int j = 1;j <= i;++j)
		{
			tri[i][j] = (tri[i-1][j] + tri[i-1][j-1])%mod;
		}
	}
	ll ans = (tri[k + 1][m + 1]%mod * Pow(b,m)%mod * Pow(a,n)%mod)%mod;
	printf("%lld",ans);
    return 0;
}

岂能尽如人意,但求无愧我心
原文地址:https://www.cnblogs.com/Zforw/p/11348292.html