CF1051D Bicolorings
Description
给定一个2×n的棋盘,可以对上面的格子黑白染色,求染色后棋盘上的联通块的个数正好为k的染色方案数
Solution
考虑状压每一列,然后就直接转移
#include<bits/stdc++.h> using namespace std; inline int read() { int f = 1 ,x = 0; char ch; do { ch = getchar(); if(ch == '-') f = -1; }while(ch < '0'||ch > '9'); do { x = (x<<3) + (x<<1) + ch - '0'; ch = getchar(); }while(ch >= '0'&&ch <= '9'); return f*x; } const int MAXN = 1000 + 10; const int MOD = 998244353; int n; int k; long long dp[MAXN][MAXN * 2][4]; int main() { n = read(),k = read(); dp[1][1][0] = dp[1][2][1] = dp[1][2][2] = dp[1][1][3] = 1; for(int i=2;i<=n;i++) { for(int j=1;j<=min(k,i*2);j++) { dp[i][j][0] = (dp[i-1][j][0] + dp[i-1][j][1] + dp[i-1][j-1][3] + dp[i-1][j][2]) % MOD; dp[i][j][1] = (dp[i-1][j-1][0] + dp[i-1][j-2][2] + dp[i-1][j-1][3] + dp[i-1][j][1]) % MOD; dp[i][j][2] = (dp[i-1][j-1][0] + dp[i-1][j-2][1] + dp[i-1][j-1][3] + dp[i-1][j][2]) % MOD; dp[i][j][3] = (dp[i-1][j][3] + dp[i-1][j][1] + dp[i-1][j-1][0] + dp[i-1][j][2]) % MOD; } } cout << (dp[n][k][0] + dp[n][k][1] + dp[n][k][2] + dp[n][k][3]) % MOD << endl; }