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. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) Solution

    A. Kitchen Utensils Water. #include <bits/stdc++.h> using namespace std; #define N 110 int n, ...

  2. hdu5102 枚举每条边的长度

    题意 给了 一颗 有 100000 个节点的树, 他们构成的边有 n*(n-1)/2 种. 每条边有一个长度,长度排序后 取前K条的 和, 枚举每条长度为1 的边 放进队列,然后通过成都为1 的表去 ...

  3. uva 10254

    如果我们设f[i]为4个柱子时把i个东东从一个柱子移到另一个柱子所用的最少步骤,设g[i]为3个柱子时对应的值,我们可以得到f[n]=min{2*f[k]+g[n-k]},其中g[i]是已知的为2^i ...

  4. myeclips破解

    MyEclipse官方安装文件,下载地址 http://www.jb51.net/softs/150886.html破解补丁http://www.jb51.net/softs/150887.html ...

  5. scp命令简单应用

    实例1:从远处复制文件到本地目录 $scp root@10.6.159.147:/opt/soft/demo.tar /opt/soft/ 说明: 从10.6.159.147机器上的/opt/soft ...

  6. Springmvc的拦截器执行顺序及各方法作用

    实现HandlerInterceptor接口或者继承HandlerInterceptor的子类,比如Spring 已经提供的实现了HandlerInterceptor 接口的抽象类HandlerInt ...

  7. 六.__FILE__ , __LINE__ 与调试日志

    很多人可能不知道,C\C++编译器提供了一套针对代码文件的宏定义,它们能够帮助开发者更好的定位代码的BUG. __FILE__ 该宏定义是一个字符串,存储着当前代码文件的完整路径 __LINE__ 该 ...

  8. supervisor管理ELK进程

    1.配置supervisor #更新epel yum install epel-release yum install python-pip pip install supervisor -p /et ...

  9. vs+qt使用资源文件

    1.在Resources目录新建一个.qrc文件 2.在解决方案的Resource Files中添加这个文件 3.为这个qrc添加资源,建议把资源都放进Resources

  10. exception disappear when forgot to await an async method

    https://github.com/aspnet/AspNetWebStack/issues/235 https://stackoverflow.com/questions/5383310/catc ...