zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    [转]Asp.net中基于Forms验证的角色验证授权
    [转]npm常用命令
    [转]utf8编码引起js输出中文乱码的解决办法
    LEFT JOIN 和 RIGHT JOIN 运算
    [转].NET 数字格式化:忽略末尾零
    [译]Pro ASP.NET MVC 3 Framework 3rd Edition 目录及说明
    微信授权登录
    百度快照更新慢怎么办
    linux爱好者必须掌握的命令,linux基础命令集合
    input输入框只能输入数字、字母相关组合(正则表达式)
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8450199.html
Copyright © 2011-2022 走看看