CF1051D Bicolorings

版权声明:大佬您能赏脸,蒟蒻倍感荣幸,还请联系我让我好好膜拜。 https://blog.csdn.net/ShadyPi/article/details/82924564

原题链接:http://codeforces.com/contest/1051/problem/D

Bicolorings

You are given a grid, consisting of 2 2 rows and n n columns. Each cell of this grid should be colored either black or white.

Two cells are considered neighbours if they have a common border and share the same color. Two cells A A and B B belong to the same component if they are neighbours, or if there is a neighbour of A A that belongs to the same component with B B .

Let’s call some bicoloring beautiful if it has exactly k k components.

Count the number of beautiful bicolorings. The number can be big enough, so print the answer modulo 998244353 998244353 .

Input

The only line contains two integers n n and k ( 1 n 1000 , 1 k 2 n ) k (1≤n≤1000, 1≤k≤2n) — the number of columns in a grid and the number of components required.

Output

Print a single integer — the number of beautiful bicolorings modulo 998244353 998244353 .

Examples
input

3 4

output

12

input

4 1

output

2

扫描二维码关注公众号,回复: 3535950 查看本文章
input

1 2

output

2

Note

One of possible bicolorings in sample 1 1 :

题解

一眼状压 d p dp 题, d p [ i ] [ j ] [ k ] dp[i][j][k] 表示前 i i 列,联通块数量为 j j ,该列的 m a s k mask k k 时的方案数,日常转移没有什么问题.

代码
#include<bits/stdc++.h>
using namespace std;
const int M=1005,mod=998244353;
long long dp[M][M<<1][4];
int n,m,i,j,k;
void in(){scanf("%d%d",&n,&m);}
void ac()
{
	dp[1][1][0]=dp[1][1][3]=dp[1][2][1]=dp[1][2][2]=1;
	for(i=1;i<n;++i)for(j=1;j<=(i<<1);++j)
	{
		for(k=0;k<4;++k)(dp[i+1][j][k]+=dp[i][j][k])%=mod;
		for(k=1;k<4;++k)(dp[i+1][j+1][k]+=dp[i][j][0])%=mod;
		for(k=1;k<3;++k)(dp[i+1][j+1][k]+=dp[i][j][3])%=mod,(dp[i+1][j][3]+=dp[i][j][k])%=mod,(dp[i+1][j][0]+=dp[i][j][k])%=mod;
		(dp[i+1][j+2][1]+=dp[i][j][2])%=mod,(dp[i+1][j+2][2]+=dp[i][j][1])%=mod,(dp[i+1][j+1][0]+=dp[i][j][3]);
	}
	printf("%lld",(dp[n][m][0]+dp[n][m][1]+dp[n][m][2]+dp[n][m][3])%mod);
}
int main(){in();ac();}

猜你喜欢

转载自blog.csdn.net/ShadyPi/article/details/82924564