【题解】Codeforces 961G Partitions
【题解】Codeforces 961G Partitions
好题啊哭了,但是如果没有不小心看了一下pdf后面一页的提示根本想不到
题意
已知\(U=\{w_i\}\),求:
\]
转换1
考虑这个\(|s|\)有点麻烦,稍微思考一下可以发现,我们最后的答案和\(w_i\)的分布没有关系,他们的贡献系数是一样的。答案只和他们的和有关。
转换2
考虑定位某个\(w_i\)对答案产生的贡献\(w_i \times p\),最后让\(\sum w\)乘上\(p\)就是答案。
然后就是喜闻乐见的套路时间了。这类与分配的集合的大小有关的计数题,可以用微扰法求出每一个元素的贡献。
考虑\(|s|\)每增大一,\(p\)就大一。考虑自己对于自己的贡献,这部分贡献就是\(\begin{Bmatrix}n\\k\end{Bmatrix}\)。
然后考虑其他元素对自己的贡献,贡献就是钦定当前选定的一个其他元素和\(w_i\)在同一集合的划分方案数,此时可以用微扰法,先让其他\(n-1\)个元素自己先划分好,然后我在直接加入有\(w_i\)的那个集合,那么一个"其他元素"的贡献就是\(\begin{Bmatrix}n-1\\k\end{Bmatrix}\)。总共有\(n-1\)个其他元素。
所以最后的答案是
\]
容斥球斯特林数即可。
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
const int mod=1e9+7;
const int maxn=2e5+5;
int jc[maxn];
int inv[maxn];
int n,s,k,ans;
inline int Pow(const int&base,const int&p){
register int ret=1;
for(register int t=p,b=base%mod;t;t>>=1,b=1ll*b*b%mod)
if(t&1) ret=1ll*ret*b%mod;
return ret;
}
inline int c(const int&n,const int&m){
if(n<m)return 0;
return 1ll*jc[n]*inv[m]%mod*inv[n-m]%mod;
}
inline int stirlin(const int&n,const int&m){
register int ret=0;
for(register int t=0,delta;t<m;++t){
delta=1ll*c(m,t)*Pow(m-t,n)%mod;
if(t&1)delta=mod-delta;
ret=(ret+delta)%mod;
}
return 1ll*ret*inv[m]%mod;
}
int main(){
jc[0]=inv[0]=1;
for(register int t=1;t<maxn;++t)
jc[t]=1ll*jc[t-1]*t%mod,inv[t]=Pow(jc[t],mod-2);
n=qr();k=qr();
for(register int t=1;t<=n;++t)
s=(s+qr()%mod)%mod;
if(s<0)s+=mod;
ans=1ll*s*(stirlin(n,k)+1ll*(n-1)*stirlin(n-1,k)%mod)%mod;
cout<<ans<<endl;
return 0;
}
【题解】Codeforces 961G Partitions的更多相关文章
- [Codeforces 961G]Partitions
Description 题库链接 给你 \(n\) 个不同的元素组成的集合 \(R\) ,每个元素有一个权值 \(w\) .对于一个子集集合 \(S\) ,它的价值为 \(W(S)=|S|\cdot\ ...
- [题解] Codeforces Round #549 (Div. 2) B. Nirvana
Codeforces Round #549 (Div. 2) B. Nirvana [题目描述] B. Nirvana time limit per test1 second memory limit ...
- 题解——CodeForces 438D The Child and Sequence
题面 D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input ...
- [题解][Codeforces]Good Bye 2019 简要题解
构造题好评,虽然这把崩了 原题解 A 题意 二人游戏,一个人有 \(k_1\) 张牌,另一个人 \(k_2\) 张,满足 \(2\le k_1+k_2=n\le 100\),每张牌上有一个数,保证所有 ...
- [题解][Codeforces]Codeforces Round #602 (Div. 1) 简要题解
orz djq_cpp lgm A 题意 给定一个分别含有 \(\frac n2\) 个左括号和右括号的括号序列 每次可以将序列的一个区间翻转 求一个不超过 \(n\) 次的操作方案,使得操作完之后的 ...
- [题解]Codeforces Round #709 (Div. 1, based on Technocup 2021 Final Round) - A. Basic Diplomacy
[题目] A. Basic Diplomacy [描述] Aleksey有n个朋友,有一个m天的假期,每天都需要一个朋友来陪他.给出每天有空的朋友的编号,要求同一个朋友来的天数不能超过m/2上取整.求 ...
- [题解]Codeforces Round #254 (Div. 2) B - DZY Loves Chemistry
链接:http://codeforces.com/contest/445/problem/B 描述:n种药品,m个反应关系,按照一定顺序放进试管中.如果当前放入的药品与试管中的药品要反应,危险系数变为 ...
- [题解]Codeforces Round #254 (Div. 2) A - DZY Loves Chessboard
链接:http://codeforces.com/contest/445/problem/A 描述:一个n*m的棋盘,有一些格子不能放棋子.现在把黑白棋子往上放,要求放满且相邻格子的棋子颜色不同.输出 ...
- [题解] Codeforces Global Round 22 1738 A B C D E F 题解
很久没rated打过cf的比赛了,这次打得还行,至少进前100了 点我看题 A. Glory Addicts 把类型0的数放进数组a里,类型1的数放进数组b里.如果\(|a|=|b|\),你可以把所有 ...
随机推荐
- Sharing Cookies --AtCoder
题目描述 Snuke is giving cookies to his three goats.He has two cookie tins. One contains A cookies, and ...
- CodeForces - 361E Levko and Strings
Discription Levko loves strings of length n, consisting of lowercase English letters, very much. He ...
- java程序容错
程序最怕出错的方式就是直接闪退 编程应该以这种方式进行,保证结构不出错,数据可容错的方式 比如 fungetsonmfrominternet(){变量 a a=从网络返回数据 return a } 在 ...
- 终端应用变身文件 MD5/SHA1 校验工具
担心下载的文件被恶意篡改?没有找到 Mac 平台文件校验工具?其实 Mac OS X 系统中已经内置了“文件 MD5/SHA1 校验工具”,它就藏身于终端(Terminal)应用中! 打开终端应用,输 ...
- Display LOV (List Of Values) Using Show_Lov In Oracle Forms
Show_Lov Function is used to display list of values (LOV) in Oracle Forms. It returns TRUE if the us ...
- EasyMvc入门教程-高级控件说明(15)方位布局控件
现在很多管理后台都流行全屏切割的布局,大体结构如下图所示: 大家注意到没,整个布局是五个部分组成:“东西南北中”,EasyMvc对应的实现的代码为: @(Html.Q().Layout().TextC ...
- java编程思想第四版第9章
练习3: public class MainTest { public static void main(String args[]){ Bcycle b=new Bcycle(); b.print( ...
- SQL must not be null(低级错误)
提醒一下: 数据库数据源配置出错,也会发生这种低级错误的.
- linux中xargs用法
参数代换: xargs xargs 是在做什么的呢?就以字面上的意义来看, x 是加减乘除的乘号,args 则是 arguments (参数) 的意思,所以说,这个玩意儿就是在产生某个命令的参数的意思 ...
- Win10蓝屏代码
UNEXPECTED_STORE_EXCEPTION “意外存储异常”是Windows 10上的“停止错误”,表示存储组件发生意外异常. 原因 固态硬盘驱动与当前固态硬盘驱动程序不兼容或是当前固态硬盘 ...