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 【组合计数+斯特林数】的更多相关文章

  1. codeforces 932E Team Work(组合数学、dp)

    codeforces 932E Team Work 题意 给定 \(n(1e9)\).\(k(5000)\).求 \(\Sigma_{x=1}^{n}C_n^xx^k\). 题解 解法一 官方题解 的 ...

  2. CF932E Team Work(第二类斯特林数)

    题目 CF932E Team Work 前置:斯特林数\(\Longrightarrow\)点这里 做法 \[\begin{aligned}\\ &\sum\limits_{i=1}^n C_ ...

  3. Codeforces 932 E Team Work ( 第二类斯特林数、下降阶乘幂、组合数学 )

    题目链接 题意 : 其实就是要求 分析 : 先暴力将次方通过第二类斯特林数转化成下降幂 ( 套路?) 然后再一步步化简.使得最外层和 N 有关的 ∑ 划掉 这里有个技巧就是 将组合数的表达式放到一边. ...

  4. 组合计数 && Stirling数

    参考: http://blog.csdn.net/qwb492859377/article/details/50654627 http://blog.csdn.net/acdreamers/artic ...

  5. 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=0n​Cn ...

  6. Codeforces 932E Team Work 数学

    Team Work 发现网上没有我这种写法.. i ^ k我们可以理解为对于每个子集我们k个for套在一起数有多少个. 那么我们问题就变成了 任意可重复位置的k个物品属于多少个子集. 然后我们枚举k个 ...

  7. CF932E Team Work——第二类斯特林数

    题解 n太大,而k比较小,可以O(k^2)做 想方设法争取把有关n的循环变成O(1)的式子 考虑用公式: 来替换i^k 原始的组合数C(n,i)一项,考虑能否和后面的系数分离开来,直接变成2^n处理. ...

  8. Codeforces 15E Triangles 【组合计数】

    Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...

  9. [CodeForces 300C Beautiful Numbers]组合计数

    题意:十进制的每一位仅由a和b组成的数是“X数”,求长度为n,各数位上的数的和是X数的X数的个数 思路:由于总的位数为n,每一位只能是a或b,令a有p个,则b有(n-p)个,如果 a*p+b*(n-p ...

随机推荐

  1. Nginx下修改wordpress固定链接后导致访问文章404

    假设我的wordpress博客是的 server{}段是直接放到放到了nginx.conf  (有的人为了方便管理,都习惯在单独写个vhost/目录来存放每个网站的配置文件,这就要根据你自己的设置来添 ...

  2. linux环境变量 export命令详解

    由host $ export DVSDK="${HOME}/ti-dvsdk_dm368-evm_xx_xx_xx_xx"引发的问题 1.${HOME}:首先, HOME 是个变量 ...

  3. Codeforces Round #358 (Div. 2) C. Alyona and the Tree dfs

    C. Alyona and the Tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  4. 第八章:部署Tornado

    到目前为止,为了简单起见,在我们的例子中都是使用单一的Tornado进程运行的.这使得测试应用和快速变更非常简单,但是这不是一个合适的部署策略.部署一个应用到生产环境面临着新的挑战,既包括最优化性能, ...

  5. Shell date 命令详解

    格式: date [选项] ... [+格式] 选项说明: -d ,--date=字符串 显示指定字符串所描述的时间 格式说明: 例子1: #!/bin/bash ##. 获取当前系统时间 YYYY- ...

  6. Learning R笔记(一)

    基本操作 帮助文档:?函数.演示:demo(函数).参数列表:formals(函数),返回为成对列表pairlist. 用all.equal函数检查浮点数是否相等,容忍度默认为1.5e-8,如果相等返 ...

  7. IE8下使用asp.net core mvc+jquery ajaxSubmit问题

    由于项目中一些特殊的地方使用了ajaxSubmit提交数据,但发现在IE8中出现问题,使用该方式提交数据后,无法返回提交结果,而是直接下载该方法名的一个文件,翻阅了园子,终于找到了最简单的解决办法,特 ...

  8. 51nod-1670-打怪兽(递推/组合数学)

    1670 打怪兽  基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题  收藏  关注 lyk在玩一个叫做“打怪兽”的游戏.游戏的规则是这样的.lyk一开始会有一个初始 ...

  9. HDU 5694 分治+规律

    http://acm.hdu.edu.cn/showproblem.php?pid=5694 此题一开始我也找到了规律,也知道是分治可是,,,想的太复杂了没写开, 我一直想的通过L,R两个参数分治,可 ...

  10. 你真的会使用Chrome开发者工具吗?

    Chrome开发工具是一个Web开发者的利器,使用它你可以实现: 管理界面元素 断点调试JavaScript代码 优化你的代码 这里将列出一些非常实用的使用技巧,帮助你更加高效的工作 1. 快速编辑H ...