传送门

题意:

求\(\displaystyle \sum_{i=0}^n{n\choose i}i^k,n\leq 10^9,k\leq 5000\)。

思路:

将\(i^k\)用第二类斯特林数展开,推导方式如:传送门

但这个题要简单一些,不用\(NTT\)预处理,直接递推就行。

详见代码:

/*
* Author: heyuhhh
* Created Time: 2019/12/12 10:42:37
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
void err() { std::cout << '\n'; }
template<typename T, typename...Args>
void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
#define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 5005, MOD = 1e9 + 7; int n, k;
int fac[N], c[N], two[N];
int s[N][N];
ll qpow(ll a, ll b) {
ll ans = 1;
while(b) {
if(b & 1) ans = ans * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return ans;
}
void run(){
cin >> n >> k;
fac[0] = 1;
for(int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
c[0] = 1;
for(int i = 1; i <= k; i++) c[i] = 1ll * c[i - 1] * (n - i + 1) % MOD * qpow(i, MOD - 2) % MOD;
two[0] = qpow(2, n);
int inv2 = qpow(2, MOD - 2);
for(int i = 1; i <= k; i++) two[i] = 1ll * two[i - 1] * inv2 % MOD;
s[0][0] = 1;
for(int i = 1; i < N; i++) {
for(int j = 1; j <= i; j++) {
s[i][j] = (1ll * j * s[i - 1][j] % MOD + s[i - 1][j - 1]) % MOD;
}
}
int ans = 0;
for(int i = 0; i <= k; i++) {
ans = (ans + 1ll * fac[i] * s[k][i] % MOD * c[i] % MOD * two[i] % MOD) % MOD;
}
cout << ans << '\n';
} int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}

最新文章

  1. 0033 Java学习笔记-反射-初步1
  2. 配置DelegatingFilterProxy使用Spring管理filter chain
  3. 微信小程序中rpx与rem单位使用
  4. Elasticsearch——使用_cat查看Elasticsearch状态
  5. Android之adb异常
  6. 李洪强iOS开发Swift篇—03_字符串和数据类型
  7. Octet string 解析
  8. Xvfb+YSlow+ShowSlow搭建前端性能测试框架 - 前端技术 | TaoBaoUED
  9. Fragment使用
  10. jquery-validate的用法
  11. wcf契约随记
  12. SpringMVC 学习-返回字符串中文乱码问题解决
  13. OO博客作业1:第1-3周作业总结
  14. Excel上传并读取数据
  15. Angular 4 父组件调用子组件中的方法
  16. 【转载】SSAS-MDX#001 - MDX 基本结构
  17. (剑指Offer)面试题54:表示数值的字符串
  18. VS2005、VS2008中的快捷键、组合键大全
  19. 手写Json转换
  20. html5 video 监听播放结束. 最好获取html标签而不是id。

热门文章

  1. 最新设计打样制作完成的FPGA视频开发板VIP—V101
  2. 使用jmeter进行接口测试
  3. 【python测试开发栈】—理解python深拷贝与浅拷贝的区别
  4. Sample Preparation by Easy Extraction and Digestion (SPEED) - A Universal, Rapid, and Detergent-free Protocol for Proteomics based on Acid Extraction(一种使用强酸的蛋白质提取方法SPEED,普适,快速,无需去垢剂)-解读人:李思奇
  5. 一次框架性能的比较,引起了我对搭建web框架的兴趣
  6. 解决Vue报错:TypeError: Cannot read property &#39;scrollHeight&#39; of undefined
  7. 成为java高手的成长历程想学好java必看
  8. linux,centos,php,word转图片方法
  9. php调用新浪API生成t.cn短网址链接
  10. 面试连环炮系列(二十一):你们的项目怎么使用kafka