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. A题:Common Substrings(KMP应用)

    原题链接 注意:2号和3号get_next()函数中next[i]赋值时的区别,一个是0,一个是1,且不能互换 #include<cstdio> #include<cstring&g ...

  2. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  3. Jsuop Whitelist

    Jsuop使用示例代码 使用jsoup HTML Cleaner 方法进行清除,但需要指定一个可配置的 Whitelist.http://jsoup.org/apidocs/org/jsoup/saf ...

  4. 日志处理(二) 日志组件logback的介绍及配置使用方法(转)

    本文转自:http://www.cnblogs.com/yuanermen/archive/2012/02/13/2348942.html http://www.cnblogs.com/yuanerm ...

  5. mongo数据库连接工具类(C#)

    Framework版本:.Net Framework 4 using System; using System.Collections.Generic; using System.Linq; usin ...

  6. web实现负载均衡的几种实现方式

    摘要: 负载均衡(Load Balance)是集群技术(Cluster)的一种应用.负载均衡可以将工作任务分摊到多个处理单元,从而提高并发处理能力.目前最常见的负载均衡应用是Web负载均衡.根据实现的 ...

  7. angular6开发不完全笔记(一) -- ng-cli

    新建项目 请在终端/控制台窗口中运行 ng -v 命令. 确定您已安装@angular/cli if没有执行 npm install -g @angular/cli 全局安装 Angular CLI. ...

  8. 如何使用AngularJS对表单提交内容进行验证

    AngularJS是一款优秀的前端JS框架,已经被用于Google的多款产品当中.它有着诸多特性,最为核心的是:MVC.模块化.自动化双向数据绑定.语义化标签.依赖注入等……使用它可以大大减少书写代码 ...

  9. pycharm同时使用python2.7版本和python3.6版本

    最近在看爬虫的专题,很多爬虫的教程是python2的,电脑上装的是3.6版本,而且python不向下兼容,这就很麻烦,最简单的print要加括号啊,等等.于是分享一个在windows环境下pychar ...

  10. "CMAKE_CXX_COMPILER-NOTFOUND"

    CMake Error: your CXX compiler: "CMAKE_CXX_COMPILER-NOTFOUND" was not found. Please set CM ...