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. VS2010/MFC编程入门之十(对话框:设置对话框控件的Tab顺序)

    前面几节鸡啄米为大家演示了加法计算器程序完整的编写过程,本节主要讲对话框上控件的Tab顺序如何调整. 上一讲为“计算”按钮添加了消息处理函数后,加法计算器已经能够进行浮点数的加法运算.但是还有个遗留的 ...

  2. Mail.Ru Cup 2018 Round 1

    A. Elevator or Stairs? 签. #include <bits/stdc++.h> using namespace std; ]; int main() { while ...

  3. showDoc的基本使用方法

    ShowDoc介绍 ShowDoc就是一个非常适合IT团队的在线文档分享工具,它可以加快团队之间沟通的效率. API文档( 查看Demo) 随着移动互联网的发展,BaaS(后端即服务)越来越流行.服务 ...

  4. RANSAC算法在图像拼接上的应用的实现

    关于算法原理请参考<基于SURF特征的图像与视频拼接技术的研究>. 一.问题提出         RANSAC的算法原理并不复杂,比较复杂的地方在于"建立模型"和&qu ...

  5. 2017-2018-1 JaWorld 团队作业--冲刺5

    2017-2018-1 JaWorld 团队作业--冲刺5(20162310) 团队项目之战斗机类分析博客 总结 我们本次团队项目设定为基于Android系统Java架构下的打飞机小游戏 游戏中所有模 ...

  6. 初识PHP(三)面向对象特性

    PHP5开始支持面向对象的编程方式.PHP的面向对象编程方法和别的语言区别不大,下面对PHP面向编程基本语法进行简单记录. 一.声明对象 声明方法: class Say{ public functio ...

  7. SqlBulkCopy 批量导入数据 转换表字段类型

    在使用SqlBulkCopy导入数据时,要有一个跟数据库里面同样的DataTable 要赋值表名 要求每个列跟数据库中列同名,并且列的类型要赋值跟数据库中列的类型对应的NET类型 要求数据库中为Nul ...

  8. SSH Secure File Transfer Client连接远程设备报“algorithm negotiation failed”错的解决方法

    SSH Secure File Transfer Client连接远程设备报"algorithm negotiation failed"错的解决方法 ssh client 报 al ...

  9. luogu P1025 数的划分

    https://www.luogu.org/problem/show?pid=1025 n的k划分 且不出现划分成0的情况  可以 分为两种情况 所有划分的数 都大于1的情况 至少划分的数里面有1的情 ...

  10. Maven简单的配置Junit测试及使用简单的mock

    1.maven依赖配置如下 <dependency> <groupId>org.mockito</groupId> <artifactId>mockit ...