• 【cf932E】E. Team Work(第二类斯特林数)


    传送门

    题意:
    (displaystyle sum_{i=0}^n{nchoose i}i^k,nleq 10^9,kleq 5000)

    思路:
    (i^k)用第二类斯特林数展开,推导方式如:传送门
    但这个题要简单一些,不用(NTT)预处理,直接递推就行。
    详见代码:

    /*
     * Author:  heyuhhh
     * Created Time:  2019/12/12 10:42:37
     */
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <vector>
    #include <cmath>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #define MP make_pair
    #define fi first
    #define se second
    #define sz(x) (int)(x).size()
    #define all(x) (x).begin(), (x).end()
    #define INF 0x3f3f3f3f
    #define Local
    #ifdef Local
      #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
      void err() { std::cout << '
    '; }
      template<typename T, typename...Args>
      void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
    #else
      #define dbg(...)
    #endif
    void pt() {std::cout << '
    '; }
    template<typename T, typename...Args>
    void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    //head
    const int N = 5005, MOD = 1e9 + 7;
    
    int n, k;
    int fac[N], c[N], two[N];
    int s[N][N];
    ll qpow(ll a, ll b) {
        ll ans = 1;
        while(b) {
            if(b & 1) ans = ans * a % MOD;
            a = a * a % MOD;
            b >>= 1;   
        }
        return ans;   
    }
    void run(){
        cin >> n >> k;
        fac[0] = 1;
        for(int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
        c[0] = 1;
        for(int i = 1; i <= k; i++) c[i] = 1ll * c[i - 1] * (n - i + 1) % MOD * qpow(i, MOD - 2) % MOD;
        two[0] = qpow(2, n);
        int inv2 = qpow(2, MOD - 2);
        for(int i = 1; i <= k; i++) two[i] = 1ll * two[i - 1] * inv2 % MOD;
        s[0][0] = 1;
        for(int i = 1; i < N; i++) {
            for(int j = 1; j <= i; j++) {
                s[i][j] = (1ll * j * s[i - 1][j] % MOD + s[i - 1][j - 1]) % MOD;
            }
        }
        int ans = 0;
        for(int i = 0; i <= k; i++) {
            ans = (ans + 1ll * fac[i] * s[k][i] % MOD * c[i] % MOD * two[i] % MOD) % MOD;   
        }
        cout << ans << '
    ';
    }
    
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);
        cout << fixed << setprecision(20);
        run();
        return 0;
    }
    
  • 相关阅读:
    springboot 整合 pagehelper
    Linux maven安装
    linux 查看端口状态
    mysql执行顺序
    Java int/int 保留2位小数
    【每日一题】30.储物点的距离 (区间处理,前缀和/线段树//树状数组)
    【每日一题】29.maze (BFS 进阶)
    2016年第七届 蓝桥杯C组 C/C++决赛题解
    2016年第七届 蓝桥杯A组 C/C++决赛题解
    第六届蓝桥杯C++A组 A~F题题解
  • 原文地址:https://www.cnblogs.com/heyuhhh/p/12052027.html
Copyright © 2020-2023  润新知