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

题干:

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441327.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

oracle内存锁,Oracle OCP之硬解析在共享池中获取内存锁的过程

(1)在父游标的名柄没有找到SQL语句的文本&#xff1a;select * from gyj_t1 where id1;2、释放library cache Latch3、获得shared pool Latch(1)搜索FreeList 空闲Chunk(2)搜索LRU上可覆盖的chunk(3)搜索R-FreeList 空闲Chunk(4)如果没空间了&#xff0c;直接ORA-04031错误4、释…

【CodeForces - 214B】Hometask (模拟,有坑)

题干&#xff1a; Furik loves math lessons very much, so he doesnt attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You ar…

php 修改文件属性命令行,Linux_linux中如何通过命令修改文件属性,ls -l即可查看目录信息-rw - phpStudy...

linux中如何通过命令修改文件属性ls -l即可查看目录信息-rwxr-xr-x 1 xura xura 1753786 2010-05-09 09:54 Grad分别对应的是&#xff1a;文件属性 连接数 文件拥有者 所属群组 文件大小 文件修改时间 文件名例如&#xff1a;d   rwx   r-x  r-x第一个字符指定了文件类型。在…

【 HDU - 1796】How many integers can you find (容斥原理,二进制枚举或者dfs)

题干&#xff1a; Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N12, and M-integer set is {2,3}, so there is another set {2,…

aix解锁oracle用户,aix用户被锁定的解决办法

原/etc/security/lastlog文件&#xff1a;oracle:time_last_login 1212750668tty_last_login /dev/pts/2host_last_login 10.126.10.200unsuccessful_login_count 18time_last_unsuccessful_login 1212750699tty_last_unsuccessful_login /dev/pts/2host_last_unsuccessf…

【CodeForces - 205B 】Little Elephant and Sorting (思维)

题干&#xff1a; The Little Elephant loves sortings. He has an array a consisting of n integers. Lets number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of…

oracle外键有什么用,深入理解Oracle索引(20):外键是否应该加索引

先表明我的立场、我是绝对支持外键一定要加索引&#xff01;虽然在高版本的Oracle里、对这个要求有所降低、但依然有如下原因&#xff1a;① 死锁外键未加索引是导致死锁的最主要原因、因为无论更新父表主键、或者删除一个父表记录、都会在子表加一个表锁这就会不必要的锁定更多…

【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)

题干&#xff1a; You are given a chessboard of size nnnn. It is filled with numbers from 11 to n2n2 in the following way: the first ⌈n22⌉⌈n22⌉ numbers from 11 to ⌈n22⌉⌈n22⌉ are written in the cells with even sum of coordinates from left to right f…

php mysql int 日期格式化 string,MYSQL int类型字段的时间存放和显示 和 php的时间存放函数...

mysql&#xff1a;int类型字段的时间存放UPDATE tablename SET add_time UNIX_TIMESTAMP(NOW())int类型字段的时间显示SELECT FROM_UNIXTIME(add_time) FROM tablenamephp时间戳函数&#xff1a;time() 获取当前时间戳 结果&#xff1a;1232553600strtotime() 转换为时间戳da…

【CodeForces - 1060C】Maximum Subrectangle (思维,预处理前缀和,dp,枚举长度)

题干&#xff1a; You are given two arrays aa and bb of positive integers, with length nn and mmrespectively. Let cc be an nmnm matrix, where ci,jai⋅bjci,jai⋅bj. You need to find a subrectangle of the matrix cc such that the sum of its elements is at m…

oracle按照指定顺序读取,oracle按照指定顺序进行排序

之前在网上查了下按照指定顺序进行排序的方法&#xff0c;根据charindex来处理排序&#xff0c;但是在oracle发现不行&#xff0c;因为oracle没有charindex函数&#xff0c;然后使用instr代替了charindex&#xff0c;然后又在网上搜了另外一种方实验如下&#xff1a;1.新建表CR…

【Codeforces 631C 】Report(单调栈,思维模拟)

题干&#xff1a; Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that d…

oracle开放视图,Oracle视图

Oracle视图在Oracle中&#xff0c;视图是实际上并不存在的虚拟表。它存储在Oracle数据字典中&#xff0c;不存储任何数据。可以在调用时执行。通过连接一个或多个表的查询创建视图。Oracle创建视图句法&#xff1a;参数&#xff1a;view_name&#xff1a;它指定要创建的Oracle …

【CodeForces - 214C 】Game (拓扑排序,思维)

题干&#xff1a; Furik and Rubik love playing computer games. Furik has recently found a new game that greatly interested Rubik. The game consists of n parts and to complete each part a player may probably need to complete some other ones. We know that th…

php$this-conn可以不先定义吗,CodeIgniter 是不是支持PDO 查询?还是本来就不支持

CodeIgniter 是否支持PDO 查询&#xff1f;还是本来就不支持&#xff1f;本帖最后由 default7 于 2014-11-15 19:34:55 编辑配置CodeIgniter 的database 连接方式为PDO 类型&#xff0c;但是怎么都查询不到数据&#xff0c;却可以查处有多少记录&#xff01;自带代码仔细跟踪代…

【ZOJ - 2836 】Number Puzzle (容斥原理)

题干&#xff1a; Given a list of integers (A1, A2, ..., An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given list. Input The input contains several test cases. …

轮番滑动PHP,touch事件之滑动判断(左右上下方向)

touch事件之滑动判断(左右上下方向)作者: 2020.03.11 本文发布于18天前 分类:$("body").on("touchstart", function(e) {// 判断默认行为是否可以被禁用if (e.cancelable) {// 判断默认行为是否已经被禁用if (!e.defaultPrevented) {e.preventDefault();}}…

【CodeForces - 215A】Bicycle Chain (水题)

题干&#xff1a; Vasyas bicycle chain drive consists of two parts: n stars are attached to the pedal axle, m stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the i-th sta…

ubuntu 在线安装php,ubuntu在线安装LNMP

一直以来个人安装lamp环境都是源码编译的&#xff0c;这个过程呢其实也要去经历的&#xff0c;但是毕竟占用时间久&#xff0c;有些时候在做一些测试环境的时候&#xff0c;可以在线安装比较快源码编译nginx可看往期&#xff1a;Nginx的安装对于lnmp的在线安装&#xff0c;如下…

【CodeForces - 215B 】Olympic Medal (数学,公式推导)

题干&#xff1a; The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of r1 cm, inner radius of r2 cm, (0 < r2 < r1)made of metal with density p1 g/cm3. The second part is an i…