Codeforces 932E Team work 【组合计数+斯特林数】
Codeforces 932E Team work
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.
Examples
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.

#include<bits/stdc++.h>
using namespace std;
#define N 5010
#define yyf 1000000007
#define LL long long
LL S[N][N],inv[N],C[N],J[N];
LL n,k;
LL fast_pow(LL a,LL b){
LL ans=1;
while(b){
if(b&1)ans=ans*a%yyf;
b>>=1;
a=a*a%yyf;
}
return ans;
}
int main(){
cin>>n>>k;
inv[0]=inv[1]=1;C[1]=n;J[1]=1;
for(LL i=2;i<=k;i++)J[i]=J[i-1]*i%yyf;
for(LL i=2;i<=k;i++)inv[i]=(yyf-yyf/i)*inv[yyf%i]%yyf;
for(LL i=2;i<=k;i++)C[i]=C[i-1]*inv[i]%yyf*(n-i+1)%yyf;
S[0][0]=1;
for(LL i=1;i<=k;i++){
S[i][0]=0;
for(LL j=1;j<=i;j++)S[i][j]=(j*S[i-1][j]%yyf+S[i-1][j-1])%yyf;
}
LL ans=0;
for(LL i=1;i<=min(k,n);i++)ans=(ans+S[k][i]*J[i]%yyf*C[i]%yyf*fast_pow(2,n-i)%yyf)%yyf;
printf("%lld",ans%yyf);
return 0;
}
Codeforces 932E Team work 【组合计数+斯特林数】的更多相关文章
- codeforces 932E Team Work(组合数学、dp)
codeforces 932E Team Work 题意 给定 \(n(1e9)\).\(k(5000)\).求 \(\Sigma_{x=1}^{n}C_n^xx^k\). 题解 解法一 官方题解 的 ...
- CF932E Team Work(第二类斯特林数)
题目 CF932E Team Work 前置:斯特林数\(\Longrightarrow\)点这里 做法 \[\begin{aligned}\\ &\sum\limits_{i=1}^n C_ ...
- Codeforces 932 E Team Work ( 第二类斯特林数、下降阶乘幂、组合数学 )
题目链接 题意 : 其实就是要求 分析 : 先暴力将次方通过第二类斯特林数转化成下降幂 ( 套路?) 然后再一步步化简.使得最外层和 N 有关的 ∑ 划掉 这里有个技巧就是 将组合数的表达式放到一边. ...
- 组合计数 && Stirling数
参考: http://blog.csdn.net/qwb492859377/article/details/50654627 http://blog.csdn.net/acdreamers/artic ...
- 2018.12.14 codeforces 932E. Team Work(组合数学)
传送门 组合数学套路题. 要求ans=∑i=0nCni∗ik,n≤1e9,k≤5000ans=\sum_{i=0}^n C_n^i*i^k,n\le 1e9,k\le 5000ans=∑i=0nCn ...
- Codeforces 932E Team Work 数学
Team Work 发现网上没有我这种写法.. i ^ k我们可以理解为对于每个子集我们k个for套在一起数有多少个. 那么我们问题就变成了 任意可重复位置的k个物品属于多少个子集. 然后我们枚举k个 ...
- CF932E Team Work——第二类斯特林数
题解 n太大,而k比较小,可以O(k^2)做 想方设法争取把有关n的循环变成O(1)的式子 考虑用公式: 来替换i^k 原始的组合数C(n,i)一项,考虑能否和后面的系数分离开来,直接变成2^n处理. ...
- Codeforces 15E Triangles 【组合计数】
Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...
- [CodeForces 300C Beautiful Numbers]组合计数
题意:十进制的每一位仅由a和b组成的数是“X数”,求长度为n,各数位上的数的和是X数的X数的个数 思路:由于总的位数为n,每一位只能是a或b,令a有p个,则b有(n-p)个,如果 a*p+b*(n-p ...
随机推荐
- Gray Code,求格林码
问题描述: The gray code is a binary numeral system where two successive values differ in only one bit. G ...
- Mac下配置NDK环境
下载NDK 这里写图片描述配置NDK开发环境 第一步:打开Mac终端 Snip20170208_1.png 第二步:在终端中输入:open -e .bash_profile,打开.bash_profi ...
- thinkphp3.2.3 + nginx 配置二级域名
使用的是阿里云centOS.74 第一步: 配置urlpath server { listen ; server_name www.xxxx.com xxxx.com; root /data/www/ ...
- cookie与session(略谈)
cookie (储存在用户本地终端上的数据) Cookie,有时也用其复数形式 Cookies,指某些网站为了辨别用户身份.进行 session 跟踪而储存在用户本地终端上的数据(通常经过加密).定义 ...
- DataContext的在控件树上的传递
控件树,在树上的每一个分支,包括叶子(比如:grid,stackpanel,lable,TextBlock)等,都有DataContext属性,并且该值可以实现从“外层”向内层传递 <Grid ...
- Nginx禁止域名恶意解析
今天打开网站发现访客人数突增啊,不对啊,小站哪来这么多的访问量呢?打开百度统计,看到有其他的域名解析到我的IP,心中很不爽啊.遂搜索之,才有了此篇文章. 打开Nginx配置文件/etc/nginx/s ...
- 常用js、jquery 语句(句型)
1.动态更改设置属性(class style 都是属性) $("#sendPhoneNum").attr("class", "n_input3&qu ...
- (转载) jQuery页面加载初始化的3种方法
jQuery 页面加载初始化的方法有3种 ,页面在加载的时候都会执行脚本,应该没什么区别,主要看习惯吧,本人觉得第二种方法最好,比较简洁. 第一种: $(document).ready(functio ...
- hdu 6063 RXD and math(快速幂)
RXD and math Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)To ...
- cursor游标(mysql)
/* 游标 cursor 什么是游标?为什么需要游标 使用存储过程对sql进行编程的时候,我们查询的语句可能是数据是多个,它总是一口气全部执行,我们无法针对每一条进行判断.也就是说,我们无法控制程序的 ...