【JSOI冬令营2019 A组, Day1T2】小 F 的星术

题目链接

Code:

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define mo 998244353
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();num=0;T f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
inline void chkmod(int &x,int y){x=(x+y)%mo;}
struct wzy{
	int nxt,vertice;
}edge[10010];
int head[5010];int len=0;
inline void add_edge(int x,int y){
	edge[++len].nxt=head[x];edge[len].vertice=y;head[x]=len;return;
}

int siz[5010];int dp[5010][5010][3];int temp[5010][3];
inline void Pretreatment(int son,int father){
	siz[son]=1;dp[son][1][0]=dp[son][0][2]=1;
	for(int i=head[son];i;i=edge[i].nxt){
		int nop=edge[i].vertice;
		if(nop==father)continue;
		Pretreatment(nop,son);
		rep(j,1,siz[son]+siz[nop]){temp[j][0]=temp[j][1]=temp[j][2]=0;}
		
		rep(j,0,siz[son]){
			rep(k,0,siz[nop]){
				int ret2=(dp[nop][k][0]+dp[nop][k][1])%mo;int ret1=(ret2+dp[nop][k][2])%mo;
				chkmod(temp[j+k][0],(1ll*dp[son][j][0]*ret1)%mo);
				if(j+k)chkmod(temp[j+k-1][1],(1ll*dp[son][j][0]*ret2)%mo);
				chkmod(temp[j+k][1],(1ll*dp[son][j][1]*ret1)%mo);
				if(j+k)chkmod(temp[j+k-1][2],(1ll*dp[son][j][1]*ret2)%mo);
				chkmod(temp[j+k][2],(1ll*dp[son][j][2]*ret1)%mo);
			} 
		}
		
		siz[son]+=siz[nop];
		rep(j,1,siz[son]){
			dp[son][j][0]=temp[j][0];dp[son][j][1]=temp[j][1];dp[son][j][2]=temp[j][2];
		}
	}
	return;
}
inline int poww(int n,int m){
	int tmp=m;int temp=n;int re_value=1;
	while(tmp){
		if(tmp&1)re_value=(1ll*re_value*temp)%mo;
		temp=(1ll*temp*temp)%mo;
		tmp>>=1;
	} 
	return re_value;
}

int main(){
	int num,n;read(num);read(n);
	rep(i,1,n-1){
		int x,y;read(x);read(y);
		add_edge(x,y);add_edge(y,x);
	}
	Pretreatment(1,0); 
	
	int ans=1;int xtq=((dp[1][1][0]+dp[1][1][1])%mo+dp[1][1][2])%mo;
	int powe=1;int power=1;
	rep(i,1,n){
		powe=(1ll*powe*i)%mo;power=(1ll*power*xtq)%mo;
		int byf=((dp[1][i][0]+dp[1][i][1])%mo+dp[1][i][2])%mo;
		chkmod(ans,(1ll*((1ll*byf*powe)%mo)*poww(power,mo-2))%mo);
	}
	write(ans);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值