CF1051D Bicolorings

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

Bicolorings

You are given a grid, consisting of 2 2 2 rows and n 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 A and B B B belong to the same component if they are neighbours, or if there is a neighbour of A A A that belongs to the same component with B B B.

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

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

Input

The only line contains two integers n n n and k ( 1 ≤ n ≤ 1000 , 1 ≤ k ≤ 2 n ) k (1≤n≤1000, 1≤k≤2n) k(1n1000,1k2n) — 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 998244353.

Examples
input

3 4

output

12

input

4 1

output

2

input

1 2

output

2

Note

One of possible bicolorings in sample 1 1 1:

题解

一眼状压 d p dp dp题, d p [ i ] [ j ] [ k ] dp[i][j][k] dp[i][j][k]表示前 i i i列,联通块数量为 j j j,该列的 m a s k mask mask k 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();}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShadyPi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值