日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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

總結

以上是生活随笔為你收集整理的【CodeForces - 1051D】Bicolorings (dp,类似状压dp)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。