• [Codeforces 932E]Team Work


    Description

    题库链接

    [sum_{i=1}^n C(n,i) imes i^k]

    (1leq nleq 10^9, 1leq kleq 5000)

    Solution

    [BZOJ 5093]图的价值的弱化版。

    看公式推导可以戳链接。

    Code

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 5000+5, yzh = 1e9+7;
    
    int S[N][N], n, k, inv[N];
    
    int quick_pow(int a, int b) {
        int ans = 1;
        while (b) {
            if (b&1) ans = 1ll*ans*a%yzh;
            b >>= 1, a = 1ll*a*a%yzh;
        }
        return ans;
    }
    void work() {
        scanf("%d%d", &n, &k);
        inv[0] = inv[1] = S[0][0] = 1;
        for (int i = 2; i <= k; i++) inv[i] = -1ll*yzh/i*inv[yzh%i]%yzh;
        for (int i = 1; i <= k; i++)
            for (int j = 1; j <= i; j++)
                S[i][j] = (1ll*S[i-1][j-1]+1ll*S[i-1][j]*j%yzh)%yzh;
        int ans = 0, C = n, fac = 1;
        for (int i = 1; i <= min(k, n); i++) {
            (ans += 1ll*fac*C%yzh*S[k][i]%yzh*quick_pow(2, n-i)%yzh) %= yzh;
            fac = 1ll*fac*(i+1)%yzh, C = 1ll*C*(n-i)%yzh*inv[i+1]%yzh;
        }
        printf("%d
    ", (ans+yzh)%yzh);
    }
    int main() {work(); return 0; }
  • 相关阅读:
    Tuesday / Wednesday = Increased Response
    脚本语言
    py2exe
    脚本语言
    访问者模式
    C调用lua脚本的效率测试
    Python编码规范
    py2exe
    Python编码规范
    访问者模式
  • 原文地址:https://www.cnblogs.com/NaVi-Awson/p/9245249.html
Copyright © 2020-2023  润新知