原题链接: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(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 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();}