原题链接:http://codeforces.com/contest/1051/problem/D
Bicolorings
You are given a grid, consisting of rows and 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 and belong to the same component if they are neighbours, or if there is a neighbour of that belongs to the same component with .
Let’s call some bicoloring beautiful if it has exactly components.
Count the number of beautiful bicolorings. The number can be big enough, so print the answer modulo .
Input
The only line contains two integers and — the number of columns in a grid and the number of components required.
Output
Print a single integer — the number of beautiful bicolorings modulo .
Examples
input
3 4
output
12
input
4 1
output
2
input
1 2
output
2
Note
One of possible bicolorings in sample :
题解
一眼状压 题, 表示前 列,联通块数量为 ,该列的 为 时的方案数,日常转移没有什么问题.
代码
#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();}