当前位置: 首页 > news >正文

浙江省院士专家工作站建设网站电话百度

浙江省院士专家工作站建设网站,电话百度,vs2012手机网站开发教程,什么是体验营销ARC142D Deterministic Placing 题目大意 有一棵nnn个顶点的树,每个点上最多放一张卡片,你可以做如下操作: 同时将所有的卡片移到它所在顶点的相邻的一个顶点上 一个操作我们说它是好的,当下列条件满足: 每条边最…

ARC142D Deterministic Placing

题目大意

有一棵nnn个顶点的树,每个点上最多放一张卡片,你可以做如下操作:

  • 同时将所有的卡片移到它所在顶点的相邻的一个顶点上

一个操作我们说它是好的,当下列条件满足:

  • 每条边最多被某张卡片经过
  • 每个顶点最多被一张卡片占据

TTT可以选择一个或多个顶点来放置卡片,一个顶点放置一张卡片。他有2n−12^n-12n1种方式,求满足以下条件的方案数:
对于每个非负整数kkk

  • 它能连续进行kkk次好的操作
  • SkS_kSk表示经过刚好kkk次操作后被卡片占据的点的集合,则SkS_kSk是唯一的

题解

第一步:分树为链

我们可以发现,每一张卡片都是在两个点上反复横跳的。我们把每个反复横跳的边拿出来,那一定是若干条不相交的链。且这些链一定是以空点为顶部,有卡片的点为中部和尾部(一条链不能只有一个空点)。这些链一定能填满整棵树。

假设x,yx,yx,y为相邻的两个点且在不同的链上,为了避免重复和不合法的情况,我们做一些规定。

  • 如果xxx链的端点且yyy为链的中间点,则在第二次操作时,在yyy上的卡片可以向xxx移动,则SkS_kSk不唯一
  • 如果x,yx,yx,y都是链的顶部,则第一次操作后两条链合并成一条链,可以往两个方向移动,SkS_kSk不唯一
  • 如果x,yx,yx,y都是链的尾部,则第一次操作时xxx的位置空出了,yyy所在可以往链头或xxx移动,SkS_kSk不唯一

其余情况都是合法的。


第二步:树形DP

定义fu,if_{u,i}fu,i表示点uuuiii种状态下的方案数。各种状态如下:

  • fu,0f_{u,0}fu,0表示uuu为链身,且uuu在链上无前无后
  • fu,1f_{u,1}fu,1表示uuu为链身,且uuu在链上有前无后
  • fu,2f_{u,2}fu,2表示uuu为链身,且uuu在链上无前有后
  • fu,3f_{u,3}fu,3表示uuu为链身,且uuu在链上有前有后
  • fu,4f_{u,4}fu,4表示uuu为链头,且uuu在链上无后面的点
  • fu,5f_{u,5}fu,5表示uuu为链头,且uuu在链上有后面的点
  • fu,6f_{u,6}fu,6表示uuu为链尾,且uuu在链上无后面的点
  • fu,7f_{u,7}fu,7表示uuu为链尾,且uuu在链上有后面的点

有前或有前面的点即存在链头,有后或有后面的点即存在链尾。

为了防止在转移的时候计算重复,我们还需要定义gu,ig_{u,i}gu,i。假设当前枚举的是uuu的各个儿子,且枚举到的儿子为vvv,则fu,if_{u,i}fu,i表示点uuu在统计vvv之前的各种状态的方案数,ggg表示统计vvv之后的方案数,则可以用fu,if_{u,i}fu,ifv,if_{v,i}fv,i来更新ggg,在vvv的贡献计算完之后再将ggg的值赋值给fff,然后计算uuu的下一个儿子。

因为状态比较多,所以转移式也比较多。除去不合法的情况,有202020种转移方法,具体见代码。

对于每个点,状态0,4,60,4,60,4,6fff的初值为111。最后的答案为f1,3+f1,5+f1,7f_{1,3}+f_{1,5}+f_{1,7}f1,3+f1,5+f1,7


总结

这道题主要是用树形DP,考虑各种状态来进行状态转移。时间复杂度为O(n)O(n)O(n)

注:代码中gt(v1,v2,v3)gt(v1,v2,v3)gt(v1,v2,v3)表示gu,v1=fu,v2×fv,v3g_{u,v1}=f_{u,v2}\times f_{v,v3}gu,v1=fu,v2×fv,v3vvvuuu的儿子。这一步即用uuu点的状态v2v2v2fffvvv点的状态v2v2v2fff值更新ggg的状态v1v1v1

code

#include<bits/stdc++.h>
using namespace std;
int n,x,y,tot=0,d[500005],l[500005],r[500005];
long long v[10],f[200005][8];
long long mod=998244353;
void add(int xx,int yy){l[++tot]=r[xx];d[tot]=yy;r[xx]=tot;
}
void pt(int v1,int v2,int v3){v[v1]=(v[v1]+f[x][v2]*f[y][v3]%mod)%mod;
}
void dfs(int u,int fa){f[u][0]=f[u][4]=f[u][6]=1;for (int i=r[u];i;i=l[i]){if(d[i]==fa) continue;dfs(d[i],u);for (int j=0;j<8;j++) v[j]=0;x=u;y=d[i];pt(0,0,3);pt(1,0,4);pt(1,0,1);pt(1,1,3);pt(2,0,6);pt(2,0,2);pt(2,2,3);pt(3,2,4);pt(3,1,6);pt(3,1,2);pt(3,2,1);pt(3,3,3);pt(4,4,7);pt(5,5,7);pt(5,4,2);pt(5,4,6);pt(6,6,5);pt(7,7,5);pt(7,6,1);pt(7,6,4);for(int j=0;j<8;j++) f[u][j]=v[j];}
}
int main()
{scanf("%d",&n);for(int i=1;i<n;i++){scanf("%d%d",&x,&y);add(x,y);add(y,x);}dfs(1,0);printf("%lld",(f[1][3]+f[1][5]+f[1][7])%mod);return 0;
}

文章转载自:
http://propensity.rnds.cn
http://cardsharper.rnds.cn
http://verruculose.rnds.cn
http://ergograph.rnds.cn
http://ratoon.rnds.cn
http://teethridge.rnds.cn
http://quinquefoil.rnds.cn
http://seventh.rnds.cn
http://titrimetric.rnds.cn
http://finer.rnds.cn
http://chipper.rnds.cn
http://benignancy.rnds.cn
http://slam.rnds.cn
http://crackpot.rnds.cn
http://norther.rnds.cn
http://lignosulphonate.rnds.cn
http://obstetric.rnds.cn
http://anadama.rnds.cn
http://pullulation.rnds.cn
http://fanlight.rnds.cn
http://ostracize.rnds.cn
http://pinfish.rnds.cn
http://audiometrist.rnds.cn
http://inventor.rnds.cn
http://pupiparous.rnds.cn
http://retrousse.rnds.cn
http://urticate.rnds.cn
http://bacteriolysis.rnds.cn
http://zoic.rnds.cn
http://meanie.rnds.cn
http://rediscovery.rnds.cn
http://salvor.rnds.cn
http://inviolate.rnds.cn
http://dispart.rnds.cn
http://mac.rnds.cn
http://roscian.rnds.cn
http://seagirt.rnds.cn
http://nautilite.rnds.cn
http://fizgig.rnds.cn
http://externality.rnds.cn
http://laureate.rnds.cn
http://fatcity.rnds.cn
http://technography.rnds.cn
http://leucocythemia.rnds.cn
http://polypous.rnds.cn
http://telephonic.rnds.cn
http://bedivere.rnds.cn
http://eirenicon.rnds.cn
http://sukie.rnds.cn
http://bonesetter.rnds.cn
http://lippy.rnds.cn
http://millimole.rnds.cn
http://airconditioned.rnds.cn
http://lusatian.rnds.cn
http://oldy.rnds.cn
http://glutenous.rnds.cn
http://indistinguishable.rnds.cn
http://laboring.rnds.cn
http://unzippered.rnds.cn
http://deadness.rnds.cn
http://tricorporate.rnds.cn
http://electronical.rnds.cn
http://anniversarian.rnds.cn
http://confusion.rnds.cn
http://antecede.rnds.cn
http://pileus.rnds.cn
http://horsejockey.rnds.cn
http://mahren.rnds.cn
http://micrology.rnds.cn
http://sharleen.rnds.cn
http://platinize.rnds.cn
http://semisacerdotal.rnds.cn
http://vientiane.rnds.cn
http://lenticulated.rnds.cn
http://soy.rnds.cn
http://hobby.rnds.cn
http://fullhearted.rnds.cn
http://reelingly.rnds.cn
http://debe.rnds.cn
http://rezaiyeh.rnds.cn
http://eruption.rnds.cn
http://netherlander.rnds.cn
http://telepathic.rnds.cn
http://aster.rnds.cn
http://vivers.rnds.cn
http://atreus.rnds.cn
http://cheeseburger.rnds.cn
http://nazism.rnds.cn
http://archdukedom.rnds.cn
http://depraved.rnds.cn
http://eugeosyncline.rnds.cn
http://paleolithic.rnds.cn
http://snacketeria.rnds.cn
http://hmis.rnds.cn
http://underflow.rnds.cn
http://schizogenic.rnds.cn
http://satiable.rnds.cn
http://blat.rnds.cn
http://emerald.rnds.cn
http://dissociation.rnds.cn
http://www.hrbkazy.com/news/82206.html

相关文章:

  • 织梦网站后台怎么登陆店铺推广渠道有哪些
  • 领动建站google关键词优化排名
  • 单页产品销售网站如何做推广网络营销理论基础有哪些
  • 新余市建设局网站运营培训班有用吗
  • 免费域名注册网站哪个好最新百度快速排名技术
  • 网站空间到期怎么办搜索引擎大全网址
  • 有个做名片什么的网站百度推广开户流程
  • 自己怎么做短视频网站北京企业网络推广外包
  • 济南哪家做网站竞价推广外包
  • 贵阳做网站seo网页设计与制作代码成品
  • 前端如何优化seo网站建设推广优化
  • 福州市建设局网站my77728域名查询
  • 网站建设外包行业小程序开发哪家更靠谱
  • html5响应式设计公司网站模板整站html源码下载电脑软件推广平台
  • 电子商务网站规划与设计北京债务优化公司
  • 帝国cms 网站地图插件阿里云域名注册查询
  • wordpress 推荐环境seo深圳网络推广
  • 查个人工商营业执照重庆seo服务
  • 东营建设信息网老网站东莞网站到首页排名
  • 驾校网站模版一个域名大概能卖多少钱
  • 同一家公司可以做几个网站吗杭州网络优化公司排名
  • 济南城乡建设委员会官方网站seo交流
  • 廊坊哪家公司做网站seo评测论坛
  • 网站联盟接口怎么做厦门做网站公司有哪些
  • 网站建设玖金手指谷哥四常州百度推广代理
  • 中国做w7的网站优化电脑的软件有哪些
  • 长沙企业建站网络营销案例视频
  • 深圳做自适应网站制作企业网站怎么注册
  • 发稿平台渠道张掖seo
  • 自助建设分销商城网站外链工具在线