首页 > 其他分享 >AtCoder Beginner Contest 248 F(连通性状压dp)

AtCoder Beginner Contest 248 F(连通性状压dp)

时间:2023-03-26 12:23:51浏览次数:53  
标签:p2 AtCoder 连通 p1 Beginner p3 int Contest dp

F 连通性状压dp

思路

看了dls的讲解后才明白一点点。
状态\(dp[i][j][k]\)表示到表示到i列,删除了j条边,点i和n-1+i是否联通,对于下一列点,
若当前i和n-1+i连通,则多出来的三条边连任意两条,使得下一列点i+1和n+i连通,否则下一列点不连通。
若当前点i和n-1+i不连通,则分情况:设上面横着的边为p1,下面横着的边为p2,最右边竖着的边为p3,首先p1和p2是必须连的(这个我想不通,可能是限制最多两个连通块),p3决定下一列点的连通性。

代码

void update(int &a,int b) 
{
	a+=b;
	if(a>=mod) a-=mod;
}

void solve() 
{
	cin>>n>>p;
	f[0][1][0]=f[0][0][1]=1;
	for(int i=0;i<n;i++) 
	{
		for(int j=0;j<n;j++) 
		{
			for(int k=0;k<2;k++) 
			{	
				if(!f[i][j][k]) continue;
				for(int x=1;x<8;x++) 
				{
					int p1=(x>>0)&1,p2=(x>>1)&1,p3=(x>>2)&1;
					if(k==0&&(!p1||!p2)) continue;
					if(k==0) update(f[i+1][j+1-p3][p3],f[i][j][k]);
					if(k==1&&(!p1&&!p2)) continue;
					if(k==1) update(f[i+1][j+3-p1-p2-p3][(p1+p2+p3)>=2],f[i][j][k]);
				}
			}
		}
	}
	for(int i=1;i<n;i++) cout<<f[n-1][i][1]<<" ";
	cout<<endl;
}

标签:p2,AtCoder,连通,p1,Beginner,p3,int,Contest,dp
From: https://www.cnblogs.com/LIang2003/p/17258425.html

相关文章

  • AtCoder Educational DP Contest
    1.A没什么难度,直接算就可以了。点击查看代码#include<bits/stdc++.h>#defineintlonglong#defineYesprintf("Yes\n")#defineNoprintf("No\n")#defineYESpr......
  • AtCoder Grand Contest 019 F Yes or No
    洛谷传送门AtCoder传送门首先容易发现最优策略是回答剩余多的选项。设\(n\)为剩余Yes的数量,\(m\)为剩余No的数量,考虑将\((n,m)\)放到平面上,若\(n>m\)则回......
  • AtCoder Grand Contest 008 F Black Radius
    洛谷传送门AtCoder传送门神题!!!!111考虑如何不重不漏地计数。先考虑全为1的情况,令\(f(u,d)\)为与\(u\)的距离\(\led\)的点集。首先单独算全集,那么对于不是全集......
  • AtCoder Beginner Contest 246
    AtCoderBeginnerContest246D题意求一个\(x\geqn\)使得\(x=a^3+a^2b+ab^2+b^3\)且\(n\leq10^{18}\)思路变形\(x=(a+b)(a^2+b^2)\),那么a、b的范围在1e6从大到小......
  • SMU Spring 2023 Trial Contest Round 1(6/8)
    SMUSpring2023TrialContestRound1(6/8)A.PrependandAppendPrependandAppend只需考虑给定字符串两端是否符合10或01即可,双指针从两端模拟即可。#include<iost......
  • AtCoder Beginner Contest 141
    AtCoderBeginnerContest141D-PowerfulDiscountTickets贪心+堆#include<bits/stdc++.h>#definelllonglongusingnamespacestd;constintN=1e5+5;......
  • [AtCoder] B - Counting Grids
      Thekeyobservationisthatthereisalwaysatmost1cellthatviolatesbothconditions. Proof: ifxviolatesbothconditions,thatmeansallothe......
  • SMU Spring 2023 Trial Contest Round 1
    A.PrependandAppend如果两段字符不同就可以删掉,如果不能删了就是最初的字符串#include<bits/stdc++.h>usingnamespacestd;voidsolve(){intn;stri......
  • AtCoder Beginner Contest 294
    题解报告基本的一些理解和问题都在注释中A:Filter//水题#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>usingnamespacestd;intm......
  • [??记录] AtCoder 练习
    3.19arc066_c(dp,观察)观察:只会在负号右边添加\((/)\)两个位置之间至多一个括号。括号不会嵌套多层。\(f[i][j]\)表示处理完\(i\)个数,有\(j\)个未匹配左括号......