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

Bicolorings

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

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

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

Input

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

Examples
input

3 4

output

12

input

4 1

output

2

input

1 2

output

2

Note

One of possible bicolorings in sample 111:

题解

一眼状压dpdpdp题,dp[i][j][k]dp[i][j][k]dp[i][j][k]表示前iii列,联通块数量为jjj,该列的maskmaskmask为kkk时的方案数,日常转移没有什么问题.

代码
#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();}

CF1051D Bicolorings相关推荐

  1. 【CodeForces - 1051D】Bicolorings (dp,类似状压dp)

    题干: You are given a grid, consisting of 22 rows and nn columns. Each cell of this grid should be col ...

  2. Codeforces 刷题记录(已停更)

    Codeforces 每日刷题记录 (已停更) 打'+'是一些有启发意义的题目,部分附上一句话题解,每日更新3题,大部分题目较水. Day ID Problem Tutorial Note 1 1 + ...

最新文章

  1. 解决cocopods不提示第三方库名字的方法
  2. 《评人工智能如何走向新阶段》后记(再续10)
  3. 解锁新姿势:探讨复杂的 if-else 语句“优雅处理”的思路
  4. run loop详解
  5. python实训报告pygame_[源码和文档分享]基于Python的PyGame库实现的2048小游戏
  6. python3 eval代码示例
  7. ER TO SQL语句
  8. webstorm 设置js或者html文件自动缩进为4个空格不生效
  9. no number java_java.lang.NumberFormatException问题!!!
  10. mininet的安装
  11. -矩阵-创建矩阵-meshgrid函数
  12. Kotlin — 适用于 Web 开发
  13. sun的EJB开发文档
  14. 如何将.sql文件导入数据库
  15. KMeans原理和密度聚类
  16. 布料仿真先导2-带阻尼的单个小球单摆下的拉格朗日方程列些和matlab仿真
  17. AIM 2020 Challenge on Learned Image Signal Processing Pipeline(个人笔记,勿喷)
  18. windows10流媒体服务器文件查看,win10的流媒体怎样启用?Win10启用流媒体的方法
  19. 和风天气开发平台使用
  20. 面向Web开发人员和网站管理员的Web缓存指南

热门文章

  1. ARTIF:实时威胁智能识别框架
  2. Hvv近期0day总结五
  3. 多个文件进行合并取前10个数(多线程方式)
  4. LinkedHashMap+Iterable实现LRU算法(简单易懂)
  5. Java多线程讲解,超详细!可获取相关笔记
  6. 编写java程序手动挡car_阅读下列说明、图和Java代码,填补空缺。[说明] 已知对某载客车辆(Car)进行类建模,如图13-2所示,其 - 赏学吧...
  7. 使用JavaMail发送邮件-从FTP读取图片并添加到邮件正文发送
  8. 禁止Chrome的缓存
  9. JAVA 如何将String进行大小写转换
  10. 细说static关键字及其应用