【z04】计算系数

这里写图片描述
【题目链接】:http://noi.qz5z.com/viewtask.asp?id=z04

【题解】

用二项式定理可以写出下列通式
这里写图片描述
组合数可以用杨辉三角搞出来;
a的x次方直接乘就好了;指数也不大.
k可能会0;
所以c[0][0]=1不要忘了;不然会WA;
a很大。平方一下可能会爆int,注意开long long

【完整代码】

#include <cstdio>
#define LL long long

using namespace std;

const int MAXN = 1000+100;
const int MOD = 10007;

int c[MAXN][MAXN];
int a,b,k,n,m;

int main()
{
    //freopen("F:\rush.txt","r",stdin);
    c[0][0] = 1;
    for (int i = 1;i <= 1000;i++)
        c[i][i] = c[i][0] = 1;
    for (int i = 1;i <= 1000;i++)
        for (int j = 1;j<= i-1;j++)
            c[i][j] = (c[i-1][j]+c[i-1][j-1])%MOD;
    scanf("%I64d%I64d%d%d%d",&a,&b,&k,&n,&m);
    LL temp = 1;
    for (int i = 1;i <= k-m;i++)
        temp = (temp*a)%MOD;
    LL temp1 = 1;
    for (int i = 1;i <= m;i++)
        temp1 = (temp1*b)%MOD;
    temp = (temp*temp1)%MOD;
    temp = (c[k][m]*temp)%MOD;
    printf("%I64d
",temp);
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7626974.html