计算系数

计算系数

https://ac.nowcoder.com/acm/problem/50585

题目链接
隐隐约约记得展开式和组合数的关系,但是记不起来,百度了才知道二项式定理。
知道二项式定理之后就是一个裸题了
答案就是

AC代码:

/*
 * @Author: hesorchen
 * @Date: 2020-04-14 10:33:26
 * @LastEditTime: 2020-06-30 22:12:29
 * @Link: https://hesorchen.github.io/
 */
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI acos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 10007
#define pll pair<ll, ll>
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))

#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define FRE                              \
    {                                    \
        freopen("in.txt", "r", stdin);   \
        freopen("out.txt", "w", stdout); \
    }

inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
//==============================================================================
ll quick_pow(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res % mod;
}
ll jc[2500];
void init()
{
    jc[0] = 1;
    for (int i = 1; i < 2345; i++)
        jc[i] = jc[i - 1] * i % mod;
}
ll C(ll n, ll m)
{
    ll a = n % mod;
    ll b = m % mod;
    if (a < b)
        return 0;
    if (a && b)
        return jc[a] * quick_pow(jc[b], mod - 2) % mod * quick_pow(jc[a - b], mod - 2) % mod * C(n / mod, m / mod) % mod;
    else
        return 1;
}
int main()
{
    ll a, b, k, n, m;
    cin >> a >> b >> k >> n >> m;
    init();
    cout << C(k, n) * quick_pow(a, n) * quick_pow(b, m) % mod << endl;
    return 0;
}
/*
*/
全部评论

相关推荐

河和静子:如果大专也能好过的话,我寒窗苦读几年的书不是白读了?
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务