CF932E Team Work

题面

题解

有一个非常玄学的公式:

$ m^n=\sum_{i=0}^nC_m^i\times S(n,i)\times i! $

看一下$\text{yyb}$的解释:

$m^n$理解为把$n$个不同的球放到$m$个不同的盒子中去。

那么我们枚举有几个盒子非空,用第二类斯特林数乘阶乘计算放置的方案数,最后求和就是结果。

所以原式等于:

$$ \sum_{i=1}^nC_n^i\sum_{j=0}^iC_i^j\times S(k,j)\times j! \\ =\sum_{i=1}^n\frac{n!}{i!(n-i)!}\sum_{j=0}^i\frac{S(k,j)}{(i-j)!} \\ =\sum_{j=0}^kS(k,j)\sum_{i=j}^n\frac{n!}{(n-i)!}*\frac{1}{(i-j)!} \\ =\sum_{j=0}^{k}S(k,j)\sum_{i=0}^n\frac{n!}{(n-j)!}\frac{(n-j)!}{(n-i)!(i-j)!} \\ =\sum_{j=0}^{k}S(k,j)\frac{n!}{(n-j)!}\sum_{i=0}^nC_{n-j}^{i-j} \\ =\sum_{j=0}^{k}S(k,j)\frac{n!}{(n-j)!}2^{n-j} $$

暴力$\text{O}(k^2)$预处理即可

代码

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#define RG register
#define file(x) freopen(#x".in", "r", stdin);freopen(#x".out", "w", stdout);
#define clear(x, y) memset(x, y, sizeof(x))

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while(ch != ‘-‘ && (!isdigit(ch))) ch = getchar();
	if(ch == ‘-‘) w = -1, ch = getchar();
	while(isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int Mod(1e9 + 7), Inv2(500000004), maxn(5010);
inline int fastpow(int x, int y)
{
	int ans = 1;
	while(y)
	{
		if(y & 1) ans = 1ll * ans * x % Mod;
		x = 1ll * x * x % Mod, y >>= 1;
	}
	return ans;
}

int n, k, S[maxn][maxn], ans;
int main()
{
#ifndef ONLINE_JUDGE
	file(cpp);
#endif
	n = read(), k = read(), S[0][0] = 1;
	for(RG int i = 1; i <= k; i++)
		for(RG int j = 1; j <= k; j++)
			S[i][j] = (S[i - 1][j - 1] + 1ll * S[i - 1][j] * j % Mod) % Mod;
	for(RG int j = 0, pow2 = fastpow(2, n), fac = 1; j <= std::min(n, k);
		pow2 = 1ll * pow2 * Inv2 % Mod, fac = 1ll * fac * (n - j) % Mod, ++j)
		ans = (ans + 1ll * S[k][j] * pow2 % Mod * fac % Mod) % Mod;
	printf("%d\n", ans);
	return 0;
}

原文地址:https://www.cnblogs.com/cj-xxz/p/10191857.html

时间: 2024-10-04 10:46:34

CF932E Team Work的相关文章

[CF932E]Team Work &amp; [BZOJ5093]图的价值

CF题面 题意:求\(\sum_{i=0}^{n}\binom{n}{i}i^k\) \(n\le10^9,k\le5000\) 模\(10^9+7\) BZOJ题面 题意:求\(n*2^{\frac{n(n-1))}{2}-(n-1)}*\sum_{i=0}^{n-1}\binom{n-1}{i}i^k\) \(n\le10^9,k\le2*10^5\) 模\(998244353\) 第二类斯特林数 赶紧去学第二类斯特林数啊 第二类斯特林数:\(S(n,m)\),表示把\(n\)个不同的的球放

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

求$\sum_{i=1}^nC_{n}^i*i^k$ 题解 1 //minamoto 2 #include<iostream> 3 #include<cstdio> 4 using namespace std; 5 const int N=5005,P=1e9+7,inv2=500000004; 6 inline int ksm(int a,int b){ 7 int res=1; 8 while(b){ 9 if(b&1) res=1ll*res*a%P; 10 a=1l

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

题解 n太大,而k比较小,可以O(k^2)做 想方设法争取把有关n的循环变成O(1)的式子 考虑用公式: 来替换i^k 原始的组合数C(n,i)一项,考虑能否和后面的系数分离开来,直接变成2^n处理. 之后大力推式子 考虑要消掉n,就想办法把n往里面放,与和n有关的项外层枚举的话,相对就不动了.可以乘法分配律把n搞定. #include<bits/stdc++.h> #define reg register int #define il inline #define numb (ch^'0')

luogu CF932E Team Work |斯特林数

一句话: 求 \(\sum^{n}_{i=1}{C(n,i)*i^k}\) 题解 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; #define ll long long const int mod=1e9+7,_=5e3+10; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c&

【CF932E】Team Work

题面 https://www.luogu.org/problem/CF932E 题解 先交换求和号.把$S2(i,j)$中$j>i$的部分去掉.再对角线替换.最后配个对$i$来说的“常数”,就把式子变成一个组合数了. #include<iostream> #include<cstdio> using namespace std; #define mod 1000000007 #define inv2 500000004 #define ri register int #def

【cf932E】E. Team Work(第二类斯特林数)

传送门 题意: 求\(\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 <algorit

UVa 1627 - Team them up!——[0-1背包]

Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every team has at least one member; every person in the team knows every other person in his team; teams are as close in their sizes

HDU 3296 &amp; POJ 3138 Acm Team Section(数学)

题目链接: HDU: http://acm.hdu.edu.cn/showproblem.php?pid=3296 POJ:  http://poj.org/problem?id=3138 Acm Team Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 159    Accepted Submission(s): 47

Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 129 Accepted Submission(s): 63   Problem Description Queues and Priority Queues are data structures which are known to most computer scie