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. saga+.net core 分布式事务处理

    Apache ServiceComb Saga 是一个微服务应用的数据最终一致性解决方案 中文官方地址:https://github.com/apache/servicecomb-saga/blob/ ...

  2. CGI-FASTCGI-PHPFPM

    随意记录,摘自知乎 原文链接:https://segmentfault.com/q/1010000000256516 首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式 ...

  3. springboot获取配置文件中的内容

    代码: GrilApplication.java @SpringBootApplication public class GrilApplication { public static void ma ...

  4. python+opencv+pyqt5控制摄像头在Qlabel上显示

    import cv2 import numpy as numpy from PIL import * import sys from PyQt5.QtWidgets import * from PyQ ...

  5. ansible入门三(Ansible的基础元素和YAML介绍)

    Ansible的基础元素和YAML介绍   本节内容: YAML Ansible常用的数据类型 Ansible基础元素 一.YAML 1. YAML介绍 YAML是一个可读性高的用来表达资料序列的格式 ...

  6. 普通用户开通sudo权限:xxx is not in the sudoers file.This incident will be reported.的解决方法

    1.切换到root用户下,怎么切换就不用说了吧,不会的自己百度去. 2.添加sudo文件的写权限,命令是: chmod u+w /etc/sudoers 3.编辑sudoers文件 vi /etc/s ...

  7. Node.js 全栈开发(二)——ES 201x 新语法的使用之基础篇

    在讲 ES 2015 新语法之前,先来说一下为什么叫 ES.JavaScript 是这门语言的名称,它有一个为它制定标准化的组织 European Computer Manufacturers Ass ...

  8. 第8课:异常处理、面向对象编程、发送邮件、url编码

    1. 异常处理 import traceback import pymysql import requests def calc(a, b): res = a / b return res def m ...

  9. 2018-2019 2 20165210 《网络对抗技术》Exp5 MSF基础

    2018-2019 2 20165210 <网络对抗技术>Exp5 MSF基础 实验内容: 一个主动攻击实践,如ms08_067(成功); 一个针对浏览器的攻击,如ms10_046(成功) ...

  10. 3. 什么是JSR参考实现? - JavaEE基础系列

    本文是JavaEE基础系列的第三节. Java EE简介 - JavaEE基础系列 JSR简介 - JavaEE基础系列 上一节中, 我们介绍了什么是JSR.JSR就是一个提交到JCP的抽象请求,包含 ...