Problem Statement

There is a tree with $N$ vertices numbered $1$ to $N$. The $i$-th edge connects vertices $A_i$ and $B_i$.

Let us keep performing the following operation until each connected component of the graph has $K$ or fewer vertices.

  • From the $N$ vertices, choose one uniformly at random that belongs to a connected component with $K+1$ or more vertices. Delete all edges with the chosen vertex as an endpoint.

Find the expected value of the number of times the operation is performed, modulo $998244353$.

How to print an expected value modulo $\text{mod }{998244353}$

It can be proved that the sought expected value is always a rational number. Additionally, under the constraints of this problem, it can also be proved that when that value is represented as an irreducible fraction $\frac{P}{Q}$, we have $Q \not \equiv 0 \pmod{998244353}$. Thus, there is a unique integer $R$ such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Report this $R$.

Constraints

  • $1 \leq K < N \leq 100$
  • $1 \leq A_i,B_i \leq N$
  • The given graph is a tree.
  • All input values are integers.

期望题首先有个经典转换:消掉连通块大于等于 $K$ 的限制,然后当我选到了一个小于 $K$ 的点就不管继续选,这样子答案是不会变的。

考虑一个大小为 \(n\),与其相邻的有 \(m\) 个点的连通块,在某一时刻操作出来的概率是 \(\frac{(n+m)!}{n!m!}\),而这些概率之和就是期望。

用树形 dp 求出来一共有多少个大小为 \(n\),与其相连的点有 \(m\) 个的连通块,分别计算即可。

#include<bits/stdc++.h>
using namespace std;
const int P=998244353,N=105;
int n,k,u,v,sz[N],in[N],jc[N],iv[N],inv[N],dp[N][N][N],hd[N],ans,e_num,f[N][N];
struct edge{
int v,nxt;
}e[N<<1];
void dfs(int x,int y)
{
dp[x][sz[x]=1][(bool)y]=1;
for(int v=hd[x];v;v=e[v].nxt)
{
if(e[v].v==y)
continue;
dfs(e[v].v,x);
for(int i=0;i<=sz[x];i++)
for(int j=0;j<=sz[x]+1;j++)
f[i][j]=dp[x][i][j],dp[x][i][j]=0;
for(int i=sz[x];~i;i--)
{
for(int j=sz[x];~j;j--)
{
for(int a=sz[e[v].v];a;a--)
for(int b=sz[e[v].v];b;b--)
(dp[x][i+a][j+b-1]+=f[i][j]*1LL*dp[e[v].v][a][b]%P)%=P;
(dp[x][i][j+1]+=f[i][j])%=P;
}
}
sz[x]+=sz[e[v].v];
}
for(int i=k+1;i<=sz[x];i++)
for(int j=0;j<=sz[x];j++)
(ans+=jc[i]*1LL*jc[j]%P*iv[i+j]%P*dp[x][i][j]%P)%=P;
/*for(int i=0;i<=sz[x];i++)
for(int j=0;j<=sz[x];j++)
if(dp[x][i][j])
printf("%d %d %d %d\n",x,i,j,dp[x][i][j]);*/
}
void add_edge(int u,int v)
{
in[u]++;
e[++e_num]=(edge){v,hd[u]};
hd[u]=e_num;
}
int main()
{
scanf("%d%d",&n,&k);
jc[0]=jc[1]=iv[0]=iv[1]=inv[1]=1;
for(int i=2;i<N;i++)
{
jc[i]=1LL*jc[i-1]*i%P;
inv[i]=1LL*(P-P/i)*inv[P%i]%P;
iv[i]=1LL*iv[i-1]*inv[i]%P;
}
for(int i=1;i<n;i++)
scanf("%d%d",&u,&v),add_edge(u,v),add_edge(v,u);
dfs(1,0);
printf("%d",ans);
}

[ARC165E] Random Isolation的更多相关文章

  1. 异常检测算法--Isolation Forest

    南大周志华老师在2010年提出一个异常检测算法Isolation Forest,在工业界很实用,算法效果好,时间效率高,能有效处理高维数据和海量数据,这里对这个算法进行简要总结. iTree 提到森林 ...

  2. Python机器学习笔记 异常点检测算法——Isolation Forest

    Isolation,意为孤立/隔离,是名词,其动词为isolate,forest是森林,合起来就是“孤立森林”了,也有叫“独异森林”,好像并没有统一的中文叫法.可能大家都习惯用其英文的名字isolat ...

  3. [转]Python机器学习笔记 异常点检测算法——Isolation Forest

    Isolation,意为孤立/隔离,是名词,其动词为isolate,forest是森林,合起来就是“孤立森林”了,也有叫“独异森林”,好像并没有统一的中文叫法.可能大家都习惯用其英文的名字isolat ...

  4. 孤立森林(Isolation Forest)

    前言随着机器学习近年来的流行,尤其是深度学习的火热.机器学习算法在很多领域的应用越来越普遍.最近,我在一家广告公司做广告点击反作弊算法研究工作.想到了异常检测算法,并且上网调研发现有一个算法非常火爆, ...

  5. 【异常检测】Isolation forest 的spark 分布式实现

    1.算法简介 算法的原始论文 http://cs.nju.edu.cn/zhouzh/zhouzh.files/publication/icdm08b.pdf .python的sklearn中已经实现 ...

  6. isolation forest进行异常点检测

    一.简介 孤立森林(Isolation Forest)是另外一种高效的异常检测算法,它和随机森林类似,但每次选择划分属性和划分点(值)时都是随机的,而不是根据信息增益或者基尼指数来选择.在建树过程中, ...

  7. [置顶] Isolation Forest算法实现详解

    本文算法完整实现源码已开源至本人的GitHub(如果对你有帮助,请给一个 star ),参看其中的 iforest 包下的 IForest 和 ITree 两个类: https://github.co ...

  8. [置顶] Isolation Forest算法原理详解

    本文只介绍原论文中的 Isolation Forest 孤立点检测算法的原理,实际的代码实现详解请参照我的另一篇博客:Isolation Forest算法实现详解. 或者读者可以到我的GitHub上去 ...

  9. Isolation Forest算法实现详解

    本文介绍的 Isolation Forest 算法原理请参看我的博客:Isolation Forest异常检测算法原理详解,本文中我们只介绍详细的代码实现过程. 1.ITree的设计与实现 首先,我们 ...

  10. (转)isolation forest进行异常点检测

    原文链接:https://www.cnblogs.com/gczr/p/9156971.html 一.简介 孤立森林(Isolation Forest)是另外一种高效的异常检测算法,它和随机森林类似, ...

随机推荐

  1. What...MiniGPT-4居然开源了,提前感受 GPT-4 的图像对话能力!

    说在前面的话: 一个月前,OpenAI向外界展示了GPT-4如何通过手绘草图直接生成网站,令当时的观众瞠目结舌. 在GPT-4发布会之后,相信大家对ChatGPT的对话能力已有所了解.圈内的朋友们应该 ...

  2. 贝塞尔曲线的切线及其AABB问题

    贝塞尔曲线的切线及其AABB问题 先聊点别的 2023 年抖音上居然还看到很多前端培训 各种直播前端教学(虽然是录播)但看起来还是有大批前往前端卷啊 说明了什么,很可能说明其它行业更难卷 这不是行业不 ...

  3. vue3 + mark.js | 实现文字标注功能

    页面效果 具体实现 新增 1.监听鼠标抬起事件,通过window.getSelection()方法获取鼠标用户选择的文本范围或光标的当前位置. 2.通过 选中的文字长度是否大于0或window.get ...

  4. c语言代码练习12

    //计算1/1-1/2+1/3...-1/100的和#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { in ...

  5. 基于Spring事件驱动模式实现业务解耦

    事件驱动模式 举个例子 大部分软件或者APP都有会有会员系统,当我们注册为会员时,商家一般会把我们拉入会员群.给我们发优惠券.推送欢迎语什么的. 值得注意的是: 注册成功后才会产生后面的这些动作: 注 ...

  6. 基于 ACK Serverless 解锁你家萌宠的 AI 形象

    基于 ACK Serverless 解锁你家萌宠的 AI 形象详情      1. 计费说明 必看!!必看!!必看!! 本实验为付费体验,需要消耗账号费用.体验后若不再需要使用,请及时释放资源,避免持 ...

  7. k8s集群部署初体验

    目录 ██ 环境准备[所有节点] ██ 安装Docker/kubeadm/kubelet[所有节点] ██ 部署 k8s master ██ 部署 k8s node ██ 部署网络插件[CNI] ██ ...

  8. the solution of Mining Your Own Business

    the description of problem (我看的是 PDF 里面的原题所以这里描述会和题目不一样,但是大意一致) 给定一个未必连通的无向图,问最少在几个点设置出口,可以保证任意一个点坍塌 ...

  9. osx12.6设置全屏

    首先安装VMWARE TOOLS就是unlocker208下的tool的darwin.iso 然后进入终端命令,这里要说一下,好多资料说按COMMAND键,反正我是没有进去,直接在vmware菜单里选 ...

  10. mysql学习之数据备份和恢复

    一.使用mysqldump进行备份 如:将test数据库备份到/tmp/mysql_back/目录下 [root@localhost tmp]# mysqldump -uroot -p111 -l - ...