CF1051D Bicolorings
Posted reverymoon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF1051D Bicolorings相关的知识,希望对你有一定的参考价值。
水题一道
$f[i][j][S]$表示$2 * i$的矩形,有$j$个联通块,某尾状态为$S$
然后转移就行了...
#include <vector> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> namespace remoon { #define re register #define de double #define le long double #define ri register int #define ll long long #define sh short #define pii pair<int, int> #define mp make_pair #define pb push_back #define tpr template <typename ra> #define rep(iu, st, ed) for(ri iu = st; iu <= ed; iu ++) #define drep(iu, ed, st) for(ri iu = ed; iu >= st; iu --) extern inline char gc() { static char RR[23456], *S = RR + 23333, *T = RR + 23333; if(S == T) fread(RR, 1, 23333, stdin), S = RR; return *S ++; } inline int read() { int p = 0, w = 1; char c = gc(); while(c > ‘9‘ || c < ‘0‘) { if(c == ‘-‘) w = -1; c = gc(); } while(c >= ‘0‘ && c <= ‘9‘) p = p * 10 + c - ‘0‘, c = gc(); return p * w; } int wr[50], rw; #define pc(iw) putchar(iw) tpr inline void write(ra o, char c = ‘ ‘) { if(!o) pc(‘0‘); if(o < 0) o = -o, pc(‘-‘); while(o) wr[++ rw] = o % 10, o /= 10; while(rw) pc(wr[rw --] + ‘0‘); pc(c); } tpr inline void cmin(ra &a, ra b) { if(a > b) a = b; } tpr inline void cmax(ra &a, ra b) { if(a < b) a = b; } tpr inline bool ckmin(ra &a, ra b) { return (a > b) ? a = b, 1 : 0; } tpr inline bool ckmax(ra &a, ra b) { return (a < b) ? a = b, 1 : 0; } } using namespace std; using namespace remoon; #define mod 998244353 inline void inc(ll &a, ll b) { a += b; if(a >= mod) a %= mod; } int n, k; ll f[1005][2010][4]; int main() { n = read(); k = read(); f[1][1][0] = 1; f[1][2][2] = 1; f[1][2][1] = 1; f[1][1][3] = 1; rep(i, 2, n) rep(j, 1, i << 1) { inc(f[i][j][0], f[i - 1][j][0] + f[i - 1][j][1] + f[i - 1][j][2] + f[i - 1][j - 1][3]); inc(f[i][j][1], f[i - 1][j - 1][0] + f[i - 1][j][1] + f[i - 1][j - 2][2] + f[i - 1][j - 1][3]); inc(f[i][j][2], f[i - 1][j - 1][0] + f[i - 1][j - 2][1] + f[i - 1][j][2] + f[i - 1][j - 1][3]); inc(f[i][j][3], f[i - 1][j - 1][0] + f[i - 1][j][1] + f[i - 1][j][2] + f[i - 1][j][3]); } ll ans = 0; inc(ans, f[n][k][0] + f[n][k][1] + f[n][k][2] + f[n][k][3]); write(ans); return 0; }
以上是关于CF1051D Bicolorings的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces - 1051D Bicolorings(DP)