码迷,mamicode.com
首页 > 其他好文 > 详细

L - Team Work

时间:2020-07-20 22:30:24      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:printf   main   as3   lang   mod   for   define   include   print   

CF932E

\[第二类斯特林数:n^k = \sum_{i=0}^{k} S_2(k,i) * C_{n}^{i} * i! \]

\[\sum_{i=0}^{n} C_{n}^{i} *i^k = \sum_{i=0}^{n}C_{n}^{i}\sum_{j=0}^{k}C_{i}^{j}*S_2(k,j)*j!\=\sum_{j=0}^{k}S_2(k,j)*j!\sum_{i=0}^{n}C_{n}^{i}*C_{i}^{j}\=\sum_{j=0}^{k}S_2(k,j)*j!\sum_{i=0}^{n}C_{n}^{j}*C_{n-j}^{n-i}\=\sum_{j=0}^{k}S_2(k,j)*j!*C_{n}^{j}\sum_{i=0}^{n}C_{n-j}^{n-i}\=\sum_{j=0}^{k}S_2(k,j)*j!*C_{n}^{j}\sum_{i=0}^{n}C_{n-j}^{i}\=\sum_{j=0}^{k}S_2(k,j)*j!*C_{n}^{j}\sum_{i=0}^{n-j}C_{n-j}^{i}\=\sum_{j=0}^{k}S_2(k,j)*j!*C_{n}^{j} * 2^{n-j}\\]


#include<bits/stdc++.h>
using namespace std;

#define int long long 

const int mod = 1e9 + 7;

int ksm(int x,int y){
    int z = 1;
    while(y){
        if(y & 1) z = z * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return z;
}

int n,k;
int s[5005][5005];

signed main(){
    scanf("%lld%lld",&n,&k);
    
    s[0][0] = 1;
    for(int i = 1; i <= k; ++ i)
    for(int j = 1; j <= k; ++ j)
    s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j % mod ) % mod;
    
    int ans = 0;
    int bas1 = 1, bas2 = 1, bas3 = ksm(2,n), inv2 = ksm(2, mod - 2);
    //bas1 j! , bas2 C(n,j), bas3 2^(n-j)
    for(int j = 0; j <= k; ++ j){
       int t = s[k][j];
       t = t * bas1 % mod;
       t = t * bas2 % mod;
       t = t * bas3 % mod;
       ans = ans + t; ans %= mod;
        
       bas1 = bas1 * (j + 1) % mod;
       bas2 = bas2 * (n - j) % mod * ksm(j + 1, mod - 2) % mod;
       bas3 = bas3 * inv2 % mod;
    }
    
    printf("%lld\n",ans);
    
    
    return 0;
}

L - Team Work

标签:printf   main   as3   lang   mod   for   define   include   print   

原文地址:https://www.cnblogs.com/zzhzzh123/p/13347231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!