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;
    }
    

      

  • 相关阅读:
    容器化的Apache服务并监控
    Jenkins配置报告与邮件插件
    Jmeter(二十八)_Docker+Jmeter+Gitlab+Jenkins+Ant(容器化的接口自动化持续集成平台)
    Jmeter(二十二)_jenkins配置gitlab插件与ant插件
    Jmeter(二十二)_脚本上传Gitlab
    Jmeter(二十七)_Beanshell保存响应内容到本地
    Jmeter(二十六)_数据驱动测试
    IT实用技术资源整理
    Jmeter(二十五)_Xpath关联
    Jmeter(二十四)_服务器性能监控
  • 原文地址:https://www.cnblogs.com/JYYHH/p/8450199.html
Copyright © 2011-2022 走看看