Team Work

发现网上没有我这种写法。。

i ^ k我们可以理解为对于每个子集我们k个for套在一起数有多少个。

那么我们问题就变成了 任意可重复位置的k个物品属于多少个子集。

然后我们枚举k个物品所占位置的个数 i , 然后需要计算有多少种方案能把k个不同物品放入i个桶中。

这个东西可以用dp[ i ][ j ] 表示 i 个物品放入 j 个桶中的方案数。 dp[ i ][ j ] = dp[ i - 1 ][ j ] * j + dp[ i - 1 ][ j - 1 ] * j

然后就可以求答案啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = + ;
const int M = 2e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; LL n, k; LL power(LL a, LL b) {
LL ans = ;
while(b) {
if(b & ) ans = ans * a % mod;
a = a * a % mod; b >>= ;
}
return ans;
} LL comb(int n, int m) {
if(n < || n < m) return ;
LL A = , B = ;
for(int i = ; i < m; i++)
A = A * (n - i) % mod, B = B * (i + ) % mod;
return A * power(B, mod - ) % mod;
} LL dp[N][N];
int main() {
for(int i = ; i < N; i++) {
for(int j = ; j <= i; j++) {
if(j == ) dp[i][j] = ;
else dp[i][j] = (dp[i-][j] * j % mod + dp[i-][j-] * j % mod) % mod;
}
}
scanf("%lld%lld", &n, &k);
LL ans = ;
for(int i = ; i <= min(n, k); i++) {
LL ret = comb(n, i);
ret = ret * power(, n - i) % mod * dp[k][i] % mod;
ans = (ans + ret) % mod;
}
printf("%lld\n", ans);
return ;
} /*
*/

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

  4. [Codeforces 932E]Team Work

    Description 题库链接 求 \[\sum_{i=1}^n C(n,i)\times i^k\] \(1\leq n\leq 10^9, 1\leq k\leq 5000\) Solution ...

  5. Codeforces 410C.Team[构造]

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

  6. CodeForces 534C Polycarpus' Dice (数学)

    题意:第一行给两个数,n 和 A,n 表示有n 个骰子,A表示 n 个骰子掷出的数的和.第二行给出n个数,表示第n个骰子所能掷出的最大的数,这些骰子都有问题, 可能或多或少的掷不出几个数,输出n个骰子 ...

  7. codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)

    题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...

  8. CF A and B and Team Training (数学)

    A and B and Team Training time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. codeforces 757F Team Rocket Rises Again

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

随机推荐

  1. 解题:UOJ #46 玄学

    题面 二进制分组,修改把区间拆开丢在后面,合并的时候归并最后两块:查询在对应节点上二分答案 #include<cstdio> #include<cstring> #includ ...

  2. acm 比赛模板

    C++模板 A-M https://pan.baidu.com/s/1lqR1s5RcAR52UJLYNfmRTQ C++模板 1-13 https://pan.baidu.com/s/1361ShU ...

  3. ReentrantLock与synchronized

    1.ReentrantLock 拥有Synchronized相同的并发性和内存语义,此外还多了 锁投票,定时锁等候和中断锁等候 线程A和B都要获取对象O的锁定,假设A获取了对象O锁,B将等待A释放对O ...

  4. Chart Controls 简介与下载

    虽然博客园已有人介绍过了,还是忍不住介绍一下微软这套免费又功能强大的图表控件「Microsoft Chart Controls for Microsoft .NET Framework 3.5」.本帖 ...

  5. 关闭ubuntu dash 方法

    因为ubuntu默认的sh是连接到dash的,又因为dash跟bash的不兼容所以出错了.执行时可以把sh换成bash 文件名.sh来执行.成功.dash是什么东西,查了一下,应该也是一种shell, ...

  6. node爬虫进阶版

    手写了一个方便爬虫的小库: const url = require('url') const glib = require('zlib') //默认头部 const _default_headers ...

  7. libvirt工具实现虚拟机管理

    libvirt工具实现虚拟机管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.介绍virt-install命令的常用参数 virt-install是一个命令行工具,它能够为K ...

  8. bzoj千题计划222:bzoj2329: [HNOI2011]括号修复(fhq treap)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2329 需要改变的括号序列一定长这样 :)))((( 最少改变次数= 多余的‘)’/2 [上取整] + ...

  9. [转载]AngularJS 开发者最常犯的 10 个错误

    http://www.oschina.net/translate/top-10-mistakes-angularjs-developers-make

  10. Mysql MERGE引擎简介

    一. 什么是MERGE引擎MERGE存储引擎把一组MyISAM数据表当做一个逻辑单元来对待,让我们可以同时对他们进行查询. 二. 应用场景如果需要把日志纪录不停的录入MySQL数据库,并且每天.每周或 ...