题干:
You are given a grid, consisting of 22 rows and nn 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 AA and BB belong to the same component if they are neighbours, or if there is a neighbour of AA that belongs to the same component with BB.
Let's call some bicoloring beautiful if it has exactly kk components.
Count the number of beautiful bicolorings. The number can be big enough, so print the answer modulo 998244353998244353.
Input
The only line contains two integers nn and kk (1≤n≤10001≤n≤1000, 1≤k≤2n1≤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 998244353998244353.
Examples
Input
3 4
Output
12
Input
4 1
Output
2
Input
1 2
Output
2
Note
One of possible bicolorings in sample 11:
题目大意:
有一个2*n的矩形块,填黑白两色的格子,问你恰好有k个连通块的填法的方案数有多少种?输入n和k。
解题报告:
题干叙述比较啰嗦,,解释了一大堆,其实就是解释的连通块。。那么dp状态转移就不难了。。(最近爱上了做dp不知道为啥,,就是喜欢找虐)
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
const ll mod = 998244353;
ll dp[1005][2010][4];//dp[i][j][k]截止到第i行,连通块数为j,且最后一列是状态k的方案数。
int main()
{int n,k;cin>>n>>k;dp[1][1][0]=dp[1][1][3]=1;dp[1][2][1]=dp[1][2][2]=1;for(int i = 2; i<=n; i++) {for(int j = 1; j<=k; j++) {//状态0-3:00 01 10 11 dp[i][j][0] = (dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j][2]+dp[i-1][j-1][3])%mod;dp[i][j][1] = (dp[i-1][j-1][0]+dp[i-1][j][1]+dp[i-1][j-2][2]+dp[i-1][j-1][3])%mod;//或者(dp[i-1][j][0]+1)+...是错的!! dp[i][j][2] = (dp[i-1][j-1][0]+dp[i-1][j][1]+dp[i-1][j-2][2]+dp[i-1][j-1][3])%mod;dp[i][j][3] = (dp[i-1][j-1][0]+dp[i-1][j][1]+dp[i-1][j][2]+dp[i-1][j][3])%mod;}}ll ans = 0;for(int i = 0; i<4; i++) {ans += dp[n][k][i];ans%=mod;}printf("%lld\n",ans);return 0 ;}
总结:
1.这题不能按照后面注释的那种写法、、、因为是表示的方案数啊,不是表示的连通块的个数!!
2.第二层循环写成for(int j = 1; j<=2*n; j++)也可以,但是这题用不到后面那些状态,这两个代码交上去,前者77ms,后者93ms