首页 > 其他分享 >300iq Contest 2 C Counting Cactus

300iq Contest 2 C Counting Cactus

时间:2023-06-01 23:46:11浏览次数:43  
标签:Counting Contest int 300iq -- 再设 Cactus 转移

这个数据范围显然是要状压的。

考虑一个子集 \(S\),钦定他的根是 \(u\) 该如何转移(设为 \(f(u,S)\)):

\(u\) 会在若干个环中,还会有若个用一条边分割的子仙人掌。

也就是若干子仙人掌拼起来。自然需要再设一个 \(g(u,S)\) 表示 \(u\) 为根,且 \(u\) 只包含在一个环或一条边中的方案数。

\(g\) 向 \(f\) 的转移是一个枚举子集,需要保证两边集合的大小关系避免算重。

为了求 \(g\),再设一个 \(h(u,v,S)\):环的起始点为 \(u\),现在加入了 \(v\)。

转移有 \(h(u,v,S\cup T)\leftarrow h(u,d,S)f(v,T)[(v,d)\in E]\)。

显然 \(u\) 处是不能算上 \(f(u,T)\) 的。

注意到一个环会被算两边,但长为 \(2\) 的不会(一条边),所以 \(h\) 向 \(g\) 的转移需要特殊处理一下。

丑陋的代码:

#include <bits/stdc++.h>
#define o(_s,_i) ((_s)>>_i&1)
using namespace std;
const int N=13,M=1<<N,mod=998244353;
int n,m,b[N][N],f[N][M],g[N][M],h[N][N][M];
inline void fix(int&x) {if(x>=mod) x-=mod;}
int main(){
	cin>>n>>m;
	for(int u,v;m--;) cin>>u>>v,u--,v--,b[u][v]=b[v][u]=1;
	for(int i=0;i<n;i++) h[i][i][1<<i]=g[i][1<<i]=1;
	for(int s=1;s<1<<n;s++){
		for(int u=0;u<n;u++) for(int v=0;v<n;v++) if(o(s,u)&&o(s,v))
			for(int t=s;t;t=(t-1)&s) if(o(t,u)&&o(t,v)&&h[u][v][t])
				for(int d=0;d<n;d++) if(o(t^s,d)&&b[v][d]) fix(h[u][d][s]+=1ll*h[u][v][t]*f[d][t^s]%mod);
		for(int u=0;u<n;u++) for(int v=0;v<n;v++) if(o(s,u)&&o(s,v)&&b[u][v])
			fix(g[u][s]+=(mod+1ll)/2*h[u][v][s]%mod);
		for(int u=0;u<n;u++) for(int v=0;v<n;v++) if(u!=v&&o(s,u)&&o(s,v)&&b[u][v])
			fix(g[u][s]+=(mod+1ll)/2*f[v][s^(1<<u)]%mod);
		for(int i=0;i<n;i++) if(o(s,i)){
			f[i][s]=g[i][s];
			for(int t=(s-1)&s;t;t=(t-1)&s) if(o(t,i)&&t!=(1<<i)){
				int p=s^t^(1<<i);
				if(t<p) fix(f[i][s]+=1ll*f[i][t]*g[i][p]%mod);
			}
		}
	}
	cout<<f[0][(1<<n)-1];
	return 0;
}

标签:Counting,Contest,int,300iq,--,再设,Cactus,转移
From: https://www.cnblogs.com/shrshrshr/p/17450545.html

相关文章

  • Row size too large. The maximum row size for the used table type, not counting B
    问题描述新建表或者修改表varchar字段长度的时候,出现这个错误Rowsizetoolarge.Themaximumrowsizefortheusedtabletype,notcountingBLOBs,is65535.Thisincludesstorageoverhead,checkthemanual.YouhavetochangesomecolumnstoTEXTorBLOBs......
  • CF1608F MEX counting
    题意给定\(n,k\)和序列\(b_{1\dotsn}\),计数序列\(a_{1\dotsn}\)使得\(\foralli\in[1,n],\operatorname{mex}\limits_{j=1}^i\{a_j\}\in[b_i-k,b_i+k]\)。数据范围:\(1\leb_i\len\le2000,0\lek\le50\)。题解永远做不出简单题。我是弱智。考虑递推......
  • LightOJ - 1058 Parallelogram Counting (数学几何&技巧)给n个点求组成平行四边形个数
    LightOJ-1058ParallelogramCountingTimeLimit: 2000MSMemoryLimit: 32768KB64bitIOFormat: %lld&%lluSubmit StatusDescriptionThereare n distinctpointsintheplane,givenbytheirintegercoordinates.Findthenumberofparallelogramswhosever......
  • Codeforces Gym 103439D - LIS Counting(猜结论+状压)
    一道需要一些猜结论技巧的中档题。首先突破口在于排列长度恰好等于不是额外输入的某个数\(k\)而是LDS与LIS的乘积,这显然启示我们去找一些性质。根据dilworth定理,最长反链等于最小链覆盖,故LIS的长度,就是最少需要的递减数列的个数使得每个元素被覆盖至少一次,而每个递减数......
  • PAT Advanced 1004. Counting Leaves
    PATAdvanced1004.CountingLeaves1.ProblemDescription:Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.2.InputSpecification:Eachinputfilecontainsonetestcase.Eachcases......
  • 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)C - Counting Stars 暴力三元环
    LittleAisanastronomylover,andhehasfoundthattheskywassobeautiful!Soheiscountingstarsnow!Therearenstarsinthesky,andlittleAhasconnectedthembymnon-directionaledges.Itisguranteedthatnoedgesconnectonestarwithi......
  • Counting Rectangles UVA - 10574
    给出n个点。问选出4个点作为定点,能够组成多少个平行与坐标轴的矩形。 点按照x排序 n^2挑选出垂直x轴的线段,按照y1排序  #include<iostream>#include<cstring>#include<algorithm>#include<vector>usingnamespacestd;constintN=1e5;structT{ intx......
  • Counting
    CountingTypeRepetitionAllowed?Formular-permutationsNo$P_n^k=r!{n\choosek}$r-combinationsNo\(C_n^k={n\chooser}\)r-permutationsYes\(n^k\)r-combinationsYes$C_{n+k-1}^k={n+k-1\choosek}$r-combinationswit......
  • 菜鸟记录:c语言实现PAT甲级1004--Counting Leaves
    好消息:与上题的Emergency是同样的方法。坏消息:又错了&&c++真的比c方便太多太多。Afamilyhierarchyisusuallypresentedbyapedigreetree.Yourjobistocountthosefamilymemberswhohavenochild.InputSpecification:Eachinputfilecontainsonetest......
  • CF1816F Xor Counting - dp - 分治 -
    题目链接:https://codeforces.com/contest/1816/problem/F题解:一道有趣的题。首先发现\(m=1\)和\(m\geq3\)时结论是平凡的。\(m=1\)时结论显然,下面讨论一下\(m\geq3\)时:首先可以构造\([x,(n-x)/2,(n-x)/2,\cdots]\),其中\(x\)和\(n\)同奇偶,显然此时异或值可以......