【AGC 005F】Many Easy Problems

本文介绍了一道关于树形结构的问题,通过树形DP和NTT(Number Theoretic Transform)来解决对于不同大小的点集求最小覆盖连通块的问题。详细解析了算法思想与实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

One day, Takahashi was given the following problem from Aoki:

You are given a tree with N vertices and an integer K. The vertices are numbered 1 through N. The edges are represented by pairs of integers (ai,bi).

For a set S of vertices in the tree, let f(S) be the minimum number of the vertices in a subtree of the given tree that contains all vertices in S.

There are C(n,k) ways to choose K vertices from the trees. For each of them, let S be the set of the chosen vertices, and find the sum of f(S) over all C(n,k) ways.

Since the answer may be extremely large, print it modulo 924844033(prime).

Since it was too easy for him, he decided to solve this problem for all K=1,2...N.

2≤N≤200000,1≤ai,bi≤N.The given graph is a tree.

Input

The input is given from Standard Input in the following format:
N
a1 b1
a2 b2
...
aN-1 bN-1

Output

Print N lines. The i-th line should contain the answer to the problem where K=i, modulo 924844033.
 

题意:给定一棵 $n$ 个节点的树,选出 $k$ 个特殊点,假设点集为 $S$,令 $f(S)$ 为最小的包含这 $k$ 个节点的连通块,分别求出 $k=1...n$ 在所有情况下的 $f(S)$ 的和。

分析:

考虑暴力,一个点被统计在连通块内,即在以它为根时,选出来的 $k$ 个点都在它的同一个儿子的子树内。即节点 $x$ 被统计进答案的次数 $g(x)$ 为:

$$g(x)=\binom{n}{k}-\sum _{(x,i)\subseteq E}\binom{sz_{i}}{k}$$

令 $cnt_{x}$ 表示上述公式里有多少个 $sz_{i}=x$,那么可以得到:

$$ans_{k}=\sum _{i=1}^{n}cnt_{i}\cdot\binom{i}{k}$$

整理可得:

$$k!\cdot ans_{k}=\sum _{i=1}^{n}\frac{cnt_{i}\cdot i!}{(i-k)!}$$

令 $a_{i}=cnt_{i}\cdot i!$$b_{i}=(n-i)!$,则可得:

$$k!\cdot ans_{k}=\sum _{i=1}^{n}a_{i}\cdot b_{n-i+k}$$

最终答案为 $n\cdot \binom{n}{k}-ans_{k}$ 

 

 1 #include<cstdio>
 2 #include<algorithm> 
 3 #include<cstring>
 4 #define LL long long
 5 using namespace std;
 6 const int N=2e5+5;
 7 const int M=524288+5;
 8 const int mod=924844033; 
 9 int n,nn,cnt,u,v,ans,first[N],fac[N],inv[N];
10 int num[N],sz[N],a[M],b[M];
11 struct edge{int to,next;}e[N*2];
12 int read()
13 {
14     int x=0,f=1;char c=getchar();
15     while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
16     while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
17     return x*f;
18 }
19 void ins(int u,int v){e[++cnt]=(edge){v,first[u]};first[u]=cnt;}
20 void dfs(int x,int fa)
21 {
22     sz[x]=1;
23     for(int i=first[x];i;i=e[i].next)
24     {
25         int to=e[i].to;
26         if(to==fa)continue;
27         dfs(to,x);
28         sz[x]+=sz[to];
29     }
30     if(fa!=-1)a[sz[x]]++,a[n-sz[x]]++;
31 }
32 int power(int a,int b)
33 {
34     int ans=1;
35     while(b)
36     {
37         if(b&1)ans=1ll*ans*a%mod;
38         a=1ll*a*a%mod;b>>=1;
39     }
40     return ans;
41 }
42 void ntt(int *a,int n,int f)
43 {
44     int k=0;while((1<<k)<n)k++;
45     for(int i=0;i<n;i++)
46     {
47         int t=0;
48         for(int j=0;j<k;j++)
49             if(i&(1<<j))t|=(1<<(k-j-1));
50         if(i<t)swap(a[i],a[t]);
51     }
52     for(int l=2;l<=n;l<<=1)
53     {
54         int m=l>>1,nw=power(5,(mod-1)/l);
55         if(f==-1)nw=power(nw,mod-2);
56         for(int *p=a;p!=a+n;p+=l)
57         {
58             int w=1;
59             for(int i=0;i<m;i++)
60             {
61                 int t=1ll*p[m+i]*w%mod;
62                 p[m+i]=(p[i]-t+mod)%mod;
63                 p[i]=(p[i]+t)%mod;
64                 w=1ll*w*nw%mod;
65             }
66         }
67     }
68     if(f==-1)
69     {
70         int inv=power(n,mod-2);
71         for(int i=0;i<n;i++)a[i]=1ll*a[i]*inv%mod;
72     }
73 }
74 int main()
75 {
76     n=read();
77     for(int i=1;i<n;i++)
78     {
79         u=read();v=read();
80         ins(u,v);ins(v,u);
81     }
82     dfs(1,-1);
83     fac[0]=1;
84     for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
85     inv[n]=power(fac[n],mod-2);
86     for(int i=n;i>=1;i--)inv[i-1]=1ll*inv[i]*i%mod;
87     for(int i=1;i<=n;i++)a[i]=1ll*a[i]*fac[i]%mod;
88     for(int i=0;i<=n;i++)b[n-i]=inv[i];
89     nn=1;while(nn<n+n+1)nn<<=1;
90     ntt(a,nn,1);ntt(b,nn,1);
91     for(int i=0;i<nn;i++)a[i]=1ll*a[i]*b[i]%mod;
92     ntt(a,nn,-1);
93     for(int i=1;i<=n;i++)
94     {
95         ans=1ll*fac[n]*inv[i]%mod*inv[n-i]%mod*n%mod;
96         printf("%lld\n",(ans-1ll*a[n+i]*inv[i]%mod+mod)%mod);
97     }
98     return 0;
99 }
View Code

 

转载于:https://www.cnblogs.com/zsnuo/p/8898265.html

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值