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 ...
随机推荐
- has~和belongsTo的区别?
在某一个class里面,class_name所对应的表为主表(父), 关系函数方法里面的第一个参数所对应的表为从属表(子), 即为与主表相关联的表. $has~ 1.外键保存在关联表中: 2.保存时 ...
- 【Python】解决Python脚本 在cmd命令行窗口运行时,中文乱码问题
问题描述 python2.X,代码中指定了UTF-8,但是在cmd命令行窗口时,打印的中文仍然会乱码 在python3不存在该问题 运行结果: 原因 搜索得知,中文windows默认的输出编码为gbk ...
- HTML 参考手册- (HTML5 标准)
HTML 参考手册- (HTML5 标准) 功能排序 New : HTML5 新标签 标签 描述 基础 <!DOCTYPE> 定义文档类型. <html> 定义一个 HT ...
- spring security3.1配置比较纠结的2个问题
转自:http://www.iteye.com/topic/1122629 总论无疑问的,spring security在怎么保护网页应用安全上做得很强很周全,但有些地方还是很差强人意,比如对< ...
- ctci1.2
; ; i < len/; i++){ tmp = *(str+i); *(str+i) = *(str+len--i); *(str+l ...
- spring mvc: 可参数化的视图控制器(在配置中指定jsp文件)MultiActionController/SimpleUrlHandlerMapping/ParameterizableViewController
spring mvc: 可参数化的视图控制器(在配置中指定jsp文件)MultiActionController/SimpleUrlHandlerMapping/ParameterizableView ...
- 1-16-2 LVM管理和ssm存储管理器使用&磁盘配额
ssm存储管理器使用&磁盘配额 ssm存储管理器使用 系统存储管理器的使用 系统存储管理器(又称ssm,即system-storage-manager),是RHEL7/CentOS7新增的功能 ...
- nyoj151——中国剩余定理
生理周期 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 142220 Accepted: 45744 Descripti ...
- tcpdump 使用实例
详细的文档见tcpdump高级过滤技巧 基本语法 ========过滤主机--------- 抓取所有经过 eth1,目的或源地址是 192.168.1.1 的网络数据# tcpdump -i eth ...
- Mac下新安装的MySQL无法登陆root用户解决方法
一 设置MySQL命令行搜索路径 0.苹果->系统偏好设置->最下边点mysql 在弹出页面中 启动mysql服务 1.打开终端,输入: sudo vi ~/.bash_profile ...