csacademy

description

有\(M\)种颜色编号为\(1-M\)。现给树上的每个点染上这\(M\)种颜色中的一种,定义一棵树是\(\mbox{colorful}\)的当且仅当这棵树上\(M\)种颜色都出现了至少一次。定义一片森林是\(\mbox{colorful}\)的当且仅当其中的每一棵树都是\(\mbox{colorful}\)的。

求\(n\)点带标号的\(\mbox{colorful}\)的森林的数量模\(924844033\)。

\(n\le10^5,m\le50\)

\(Hint:924844033=2^{21}\times441+1\),它的原根是\(5\)。

sol

首先求出\(n\)点构成一棵\(\mbox{colorful}\)的树的方案数\(g_n\)。

\[g_n=\begin{cases}1&n=1\\n^{n-2} \times S(n,m) \times m!&n\ge2\end{cases}
\]

\(n^{n-2}\)是带标号完全图生成树的方案数,后面的第二类斯特林数乘阶乘的组合意义就是把\(n\)个不同的球放入\(m\)个不同的盒子里且不允许空盒的方案数。

然后设\(f_n\)表示答案,考虑新加入的第\(n\)号点和那些点连通构成一棵树:

\[f_n=\sum_{i=1}^ng_i\binom{n-1}{i-1}f_{n-i}
\]

把组合数拆开就是一个卷积的形式,直接分治法法塔即可。复杂度\(O(n\log^2n)\)

懒得写求逆了

code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
const int N = 4e5+5;
const int mod = 924844033;
int n,m,jc[N],jcn[N],S[N][105],g[N],f[N],rev[N],og[N],x[N],y[N];
int fastpow(int a,int b){
int res=1;
while(b){if(b&1)res=1ll*res*a%mod;a=1ll*a*a%mod;b>>=1;}
return res;
}
void ntt(int *P,int opt,int len){
int l=0;while((1<<l)<len)++l;--l;
for (int i=0;i<len;++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<l);
for (int i=0;i<len;++i) if (i<rev[i]) swap(P[i],P[rev[i]]);
for (int i=1;i<len;i<<=1){
int W=fastpow(5,(mod-1)/(i<<1));
if (opt==-1) W=fastpow(W,mod-2);
og[0]=1;for (int j=1;j<i;++j) og[j]=1ll*og[j-1]*W%mod;
for (int p=i<<1,j=0;j<len;j+=p)
for (int k=0;k<i;++k){
int x=P[j+k],y=1ll*og[k]*P[j+k+i]%mod;
P[j+k]=(x+y)%mod;P[j+k+i]=(x-y+mod)%mod;
}
}
if (opt==-1) for (int i=0,Inv=fastpow(len,mod-2);i<len;++i) P[i]=1ll*P[i]*Inv%mod;
}
void solve(int l,int r){
if (l==r) return;int mid=l+r>>1;solve(l,mid);
int len=1;while(len<=r-l+1)len<<=1;
for (int i=0;i<len;++i) x[i]=y[i]=0;
for (int i=l;i<=mid;++i) x[i-l]=1ll*f[i]*jcn[i]%mod;
for (int i=1;i<=r-l;++i) y[i-1]=1ll*g[i]*jcn[i-1]%mod;
ntt(x,1,len);ntt(y,1,len);
for (int i=0;i<len;++i) x[i]=1ll*x[i]*y[i]%mod;
ntt(x,-1,len);
for (int i=mid+1;i<=r;++i) f[i]=(f[i]+1ll*x[i-l-1]*jc[i-1])%mod;
solve(mid+1,r);
}
int main(){
n=gi();m=gi();
jc[0]=jcn[0]=1;
for (int i=1;i<=n;++i) jc[i]=1ll*jc[i-1]*i%mod;
jcn[n]=fastpow(jc[n],mod-2);
for (int i=n;i;--i) jcn[i-1]=1ll*jcn[i]*i%mod;
S[0][0]=1;
for (int i=1;i<=n;++i)
for (int j=1;j<=i&&j<=m;++j)
S[i][j]=(1ll*S[i-1][j]*j+S[i-1][j-1])%mod;
for (int i=1;i<=n;++i)
g[i]=1ll*(i==1?1:fastpow(i,i-2))*S[i][m]%mod*jc[m]%mod;
f[0]=1;solve(0,n);
for (int i=1;i<=n;++i) printf("%d\n",f[i]);return 0;
}

[CSAcademy]Colored Forests的更多相关文章

  1. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...

  2. poj 2513 Colored Sticks trie树+欧拉图+并查集

    点击打开链接 Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 27955   Accepted ...

  3. Machine Learning Methods: Decision trees and forests

    Machine Learning Methods: Decision trees and forests This post contains our crib notes on the basics ...

  4. POJ 2513 Colored Sticks

    Colored Sticks Time Limit: 5000MS   Memory Limit: 128000K Total Submissions: 28036   Accepted: 7428 ...

  5. poj.2419.Forests (枚举 + set用法)

    Forests Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5782   Accepted: 2218 Descripti ...

  6. 周赛-Colored Sticks 分类: 比赛 2015-08-02 09:33 7人阅读 评论(0) 收藏

    Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 32423 Accepted: 8556 Desc ...

  7. codeforces 553A . Kyoya and Colored Balls 组合数学

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  8. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合

    C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. 随机森林——Random Forests

    [基础算法] Random Forests 2011 年 8 月 9 日 Random Forest(s),随机森林,又叫Random Trees[2][3],是一种由多棵决策树组合而成的联合预测模型 ...

随机推荐

  1. Git 系列——第一步安装 Git

    之前也没有用过什么版本控制的工具,唯一用过的就是 SVN 了,不过也只是简单的使用而已,比如写好代码就签入,没了?是的,没了. 于是接触到了 Git 这个分布式版本控制软件,接下来就让我们好好学习,天 ...

  2. 五,动态库(dll)的封装与使用

    在项目开发中,我们经常会使用到动态库(dll),要么是使用别人的动态库,要么是将功能函数封装为动态库给别人用.那么如何封装和使用动态库呢?以下内容为你讲解. 1.动态库的封装 以vs2010为例,我们 ...

  3. linux体系结构与内核结构图解

    1.当被问到Linux体系结构(就是Linux系统是怎么构成的)时,我们可以参照下图这么回答:从大的方面讲,Linux体系结构可以分为两块: (1)用户空间:用户空间中又包含了,用户的应用程序,C库 ...

  4. install_github安装错误解决方法

    install.packages('devtools')library(devtools)install_github('hdng/clonevol') Installation failed: Ti ...

  5. codeforces 11 B.Jumping Jack 想法题

    B. Jumping Jack Jack is working on his jumping skills recently. Currently he's located at point zero ...

  6. Prototype(原型)

    意图: 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 适用性: 当要实例化的类是在运行时刻指定时,例如,通过动态装载:或者为了避免创建一个与产品类层次平行的工厂类层次时:或者当一个 ...

  7. QWebView_QWebEngineView

    1.http://stackoverflow.com/questions/29055475/qwebview-or-qwebengineview “ QWebView uses WebKit as t ...

  8. $.proxy用法详解

    jQuery中的$.proxy官方描述为: 描述:接受一个函数,然后返回一个新函数,并且这个新函数始终保持了特定的上下文语境. 官方API: jQuery.proxy( function, conte ...

  9. vue双向数据绑定最最最最最简单直观的例子

    vue双向数据绑定最最最最最简单直观的例子 一.总结 一句话总结:双向绑定既不仅model可以影响view的数据,view也可以影响model的数据 view model 数据 1.vue双向数据绑定 ...

  10. 使用actioncable做的notification(GoRails教学,2课)

    GoRails视频系列: 1.   用actioncable建立Notifications 2.  见博客: 3.  非认证/登陆user不能使用actioncable 用ActionCable 建立 ...