Description

题库链接

\[\sum_{i=1}^n C(n,i)\times i^k\]

\(1\leq n\leq 10^9, 1\leq k\leq 5000\)

Solution

[BZOJ 5093]图的价值的弱化版。

看公式推导可以戳链接。

Code

#include <bits/stdc++.h>
using namespace std;
const int N = 5000+5, yzh = 1e9+7; int S[N][N], n, k, inv[N]; int quick_pow(int a, int b) {
int ans = 1;
while (b) {
if (b&1) ans = 1ll*ans*a%yzh;
b >>= 1, a = 1ll*a*a%yzh;
}
return ans;
}
void work() {
scanf("%d%d", &n, &k);
inv[0] = inv[1] = S[0][0] = 1;
for (int i = 2; i <= k; i++) inv[i] = -1ll*yzh/i*inv[yzh%i]%yzh;
for (int i = 1; i <= k; i++)
for (int j = 1; j <= i; j++)
S[i][j] = (1ll*S[i-1][j-1]+1ll*S[i-1][j]*j%yzh)%yzh;
int ans = 0, C = n, fac = 1;
for (int i = 1; i <= min(k, n); i++) {
(ans += 1ll*fac*C%yzh*S[k][i]%yzh*quick_pow(2, n-i)%yzh) %= yzh;
fac = 1ll*fac*(i+1)%yzh, C = 1ll*C*(n-i)%yzh*inv[i+1]%yzh;
}
printf("%d\n", (ans+yzh)%yzh);
}
int main() {work(); 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. Codeforces 932E Team work 【组合计数+斯特林数】

    Codeforces 932E Team work You have a team of N people. For a particular task, you can pick any non-e ...

  3. Codeforces 932E Team Work 数学

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

  4. 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 ...

  5. Codeforces 410C.Team[构造]

    C. Team time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  6. codeforces 757F Team Rocket Rises Again

    链接:http://codeforces.com/problemset/problem/757/F 正解:灭绝树. mdzz倍增lca的根节点深度必须是1..我因为这个错误调了好久. 我们考虑先求最短 ...

  7. Codeforces 401C Team 贪心法

    本题使用贪心法.关键是考贪心策略.同一时候要求要细心,我提交的时候也WA了几次.大意题目就是怎样依照给定的规则排列一个01字符串,引用原题例如以下: C. Team time limit per te ...

  8. codeforces C. Team 解题报告

    题目链接:http://codeforces.com/problemset/problem/401/C 题目意思:给出0和1的数目(分别为n和m个),问是否能构造一条同时满足连续两个0不能再一起和连续 ...

  9. Codeforces 985G - Team Players(三元环)

    Codeforces 题目传送门 & 洛谷题目传送门 真·ycx 做啥题我就做啥题 考虑枚举 \(j\),我们预处理出 \(c1_i\) 表示与 \(i\) 相连的编号 \(<i\) 的 ...

随机推荐

  1. LeetCode139:Word Break

    题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-se ...

  2. Backup--还原选项之STANDBY

    很多DBA对还原时制定RECOVERY 与 NORECOVERY选项都很熟悉,但是对于STANDBY就有点茫然了,今天一起来学习下吧. --============================== ...

  3. 设计模式之命令模式(Command Pattern)

    一.什么是命令模式? 命令模式,封装了方法调用细节,以解耦请求者与执行者,具体流程如下: 1.从请求者(客户)的角度看 请求者(客户)发出请求 -> 调用者(系统)构造命令对象封装请求 -> ...

  4. App.config使用方法(基础教程)

    WPF程序中的App.config文件是应用程序中经常使用的一种配置文件,System.Configuration.dll文件中提供了大量的读写的配置,是一种很高效的程序配置方式. 1.首先在工程中配 ...

  5. wpf简单进度条

    UserControl x:Class="WpfApplication1.UserControl2" xmlns="http://schemas.microsoft.co ...

  6. Python面向对象(特殊成员)

    day25 __init__     类()自动执行     __del__     __call__     对象()  类()() 自动执行     __int__      int(对象)    ...

  7. linux parallel rsync 拷贝N多文件

    先来个对比图看一下, 左边图是普通 rsync 目录拷贝, 右边图是借助 parallel 工具并发起了多个 rsync centos6.5安装 parallel #!/bin/bash # Inst ...

  8. 怎样优化调整innodb_log_buffer_size

    官方文档并没有直接告诉如何调整 innodb_log_buffer_size 大小, 根据对mysql 的状态信息了解知道  innodb_log_buffer_size 跟 Innodb_os_lo ...

  9. logcat -- 基本用法

    1.Log类是一个日志类,我们可以在代码中使用logcat打印出消息 常见的日志记录方法有: v(String,String)  --verbose 显示全部信息 d(String,String) - ...

  10. django第三课 模版

    第一步 创建项目文件: django-admin.py startproject *** 第二步 进入该文件下创建文件夹templates,在该文件夹下创建thanks.html <!DOCTY ...