• Codeforces 932 E Team Work


    Discription

    You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is xk.

    Output the sum of costs over all non-empty subsets of people.

    Input

    Only line of input contains two integers N (1 ≤ N ≤ 109) representing total number of people and k (1 ≤ k ≤ 5000).

    Output

    Output the sum of costs for all non empty subsets modulo 109 + 7.

    Example

    Input
    1 1
    Output
    1
    Input
    3 2
    Output
    24

    Note

    In the first example, there is only one non-empty subset {1} with cost 11 = 1.

    In the second example, there are seven non-empty subsets.

    {1} with cost 12 = 1

    {2} with cost 12 = 1

    {1, 2} with cost 22 = 4

    {3} with cost 12 = 1

    {1, 3} with cost 22 = 4

    {2, 3} with cost 22 = 4

    {1, 2, 3} with cost 32 = 9

    The total cost is 1 + 1 + 4 + 1 + 4 + 4 + 9 = 24.

    题目大意就是要你求一下ΣC(n,i)*i^k。

    然后直接上我推的式子了(就是用第二类斯特林数代换一下)

    (怎么这个图这么大。。。。不管了)

    然后就开开心心A了。

    不过好像k再大一点也可以做,,,就是要用FFT 在N log N的时间求出某一行的斯特林数了(反正我也不会hhhh),不能再N^2递推斯特林数了。

    (后记:现在会NTT 在 N log N求某一行斯特林数了,请见 : http://www.cnblogs.com/JYYHH/p/8641094.html)

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<algorithm>
    #include<cstring>
    #define ll long long
    #define maxn 5005
    using namespace std;
    const int ha=1000000007;
    const int inv=ha/2+1;
    int S[maxn],n,m;
    int ans=0,tmp,ci;
    
    inline void init(){
    	S[1]=1;
    	for(int i=2;i<=m;i++)
    	    for(int j=i;j;j--){
    	    	S[j]=(S[j]*(ll)j+(ll)S[j-1])%ha;
    		}
    }
    
    inline int ksm(int x,int y){
    	int an=1;
    	for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
    	return an;
    }
    
    inline void solve(){
    	tmp=1,ci=ksm(2,n);
    	for(int i=1;i<=m;i++){
    		tmp=tmp*(ll)(n-i+1)%ha;
    		ci=ci*(ll)inv%ha;
    		ans=((ll)ans+S[i]*(ll)tmp%ha*(ll)ci)%ha;
    	}
    }
    
    int main(){
    	scanf("%d%d",&n,&m);
    	init();
    	solve();
    	printf("%d
    ",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    科技巨头争抢的“超级账本”,到底是个什么组织?
    区块链结合教育,将给教育行业带来哪些变革?
    国家区块链战略开启,教育行业应对几何?
    区块链如何改变教育
    区块链技术在教育领域的应用模式与现实挑战
    知乎-区块链技术运用于教育有多少种可能?
    区块链+教育,让教育行业充满希望
    教育区块链应用案例【2019】
    区块链在教育行业的落地应用现状介绍
    PowerShell 搜索文件编码格式
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8450199.html
Copyright © 2020-2023  润新知