codeforces 1051D. Bicolorings

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

Copy

3 4

output

Copy

12

input

Copy

4 1

output

Copy

2

input

Copy

1 2

output

Copy

2

Note

One of possible bicolorings in sample 11:

英语太渣,题意看了好一会,才发现是问的是连通块K个的着色方案

题意知道就比较明显的线性DP了(还有点状压的思想),行数固定2应该是故意降低难度了

DP三维,列数/连通块个数/当前列状态

当前列用二进制表示,就00,01,10,11四个状态

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1005][2005][4];
const int mo = 998244353;
int main(){
    int n,m,i,j,k,ans,num,sum,len,ends,p,q;
    while(~scanf("%d%d",&n,&m)){
        num=0;
        memset(dp,0,sizeof dp);
        dp[1][1][0]=dp[1][1][3]=1;
        dp[1][2][1]=dp[1][2][2]=1;
        for(j=2;j<=n;j++){
            for(k=1;k<=2*j;k++){
                dp[j][k][0]=(dp[j-1][k-1][3]+dp[j-1][k][0]+dp[j-1][k][1]+dp[j-1][k][2])%mo;
                dp[j][k][1]=(dp[j-1][k-1][0]+dp[j-1][k][1]+dp[j-1][k-2][2]+dp[j-1][k-1][3])%mo;
                dp[j][k][2]=(dp[j-1][k-1][0]+dp[j-1][k-2][1]+dp[j-1][k][2]+dp[j-1][k-1][3])%mo;
                dp[j][k][3]=(dp[j-1][k-1][0]+dp[j-1][k][1]+dp[j-1][k][2]+dp[j-1][k][3])%mo;
            }
        }
        printf("%lld\n",(dp[n][m][0]+dp[n][m][1]+dp[n][m][2]+dp[n][m][3])%mo);
    }
    return 0;
}

long long 随手开的,怕加法过程9*1e8*4直接炸,变量定义了好多没用的,其实是区间DP遗留。。。

初始状态记得要自己设

然后后续尽量更区间DP,区间DP着实感觉太重要了,在此推荐2001国家集训队毛子青的论文,对动态规划的优化一块讲得挺不错的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值