From 2b86fac755a6e523de2e2f459786bc5d1858244c Mon Sep 17 00:00:00 2001 From: Cenyue Zhang <47886494+GoatGirl98@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:23:44 +0800 Subject: [PATCH] =?UTF-8?q?Create=20BUAAOJ124=20=E7=8A=B6=E5=8E=8BDP+?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E9=99=8D=E7=BB=B4=E4=BC=98=E5=8C=96.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\347\273\264\344\274\230\345\214\226.cpp" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "2014\347\272\247-\350\275\257\344\273\266\345\255\246\351\231\242-\347\256\227\346\263\225\345\210\206\346\236\220\344\270\216\350\256\276\350\256\241/E1-\347\256\227\346\263\225\347\273\203\344\271\240\350\265\233/BUAAOJ124 \347\212\266\345\216\213DP+\346\273\232\345\212\250\351\231\215\347\273\264\344\274\230\345\214\226.cpp" diff --git "a/2014\347\272\247-\350\275\257\344\273\266\345\255\246\351\231\242-\347\256\227\346\263\225\345\210\206\346\236\220\344\270\216\350\256\276\350\256\241/E1-\347\256\227\346\263\225\347\273\203\344\271\240\350\265\233/BUAAOJ124 \347\212\266\345\216\213DP+\346\273\232\345\212\250\351\231\215\347\273\264\344\274\230\345\214\226.cpp" "b/2014\347\272\247-\350\275\257\344\273\266\345\255\246\351\231\242-\347\256\227\346\263\225\345\210\206\346\236\220\344\270\216\350\256\276\350\256\241/E1-\347\256\227\346\263\225\347\273\203\344\271\240\350\265\233/BUAAOJ124 \347\212\266\345\216\213DP+\346\273\232\345\212\250\351\231\215\347\273\264\344\274\230\345\214\226.cpp" new file mode 100644 index 0000000..8847381 --- /dev/null +++ "b/2014\347\272\247-\350\275\257\344\273\266\345\255\246\351\231\242-\347\256\227\346\263\225\345\210\206\346\236\220\344\270\216\350\256\276\350\256\241/E1-\347\256\227\346\263\225\347\273\203\344\271\240\350\265\233/BUAAOJ124 \347\212\266\345\216\213DP+\346\273\232\345\212\250\351\231\215\347\273\264\344\274\230\345\214\226.cpp" @@ -0,0 +1,54 @@ +#include +#include +#include +typedef long long i64; +const int M = 110; +const int N = 10, S = (1 << N); +int m, n, slim; + +inline bool judge_sta(int sta) { return ((sta & (sta >> 1)) == 0) && ((sta & (sta >> 2)) == 0); } +inline bool judge_trans(int st, int ed) { return (st & ed) == 0; } // trans 1 row + +std::vector ok_sta; +std::vector pre_sta[S + 10]; + +int popcnt[S + 10]; +int dp[2][S + 10][S + 10]; // lst/now, cursta, presta +int lst, now; + +inline void init_popcnt() { for (int i = 0; i < S; ++i) popcnt[i] = __builtin_popcount(i); } + +void clr() +{ + for (int& cur : ok_sta) for (int& pre : pre_sta[cur]) dp[0][cur][pre] = dp[1][cur][pre] = 0; + ok_sta.clear(); for (int i = 0; i < slim; ++i) pre_sta[i].clear(); +} + +void solve() +{ + slim = (1 << n); + for (int s = 0; s < slim; ++s) if (judge_sta(s)) ok_sta.push_back(s); + for (int& cur : ok_sta) for (int& pre : ok_sta) if (judge_trans(pre, cur)) pre_sta[cur].push_back(pre); + lst = 0, now = 1; + for (int i = 1; i <= m; ++i, lst = 1 - lst, now = 1 - now) + { + for (int& cur : ok_sta) + for (int& pre : pre_sta[cur]) + { + if (i == 1 && pre) continue; + dp[now][cur][pre] = 0; + for (int& prepre : pre_sta[pre]) + if (judge_trans(prepre, cur)) + dp[now][cur][pre] = std::max(dp[now][cur][pre], dp[lst][pre][prepre] + popcnt[cur]); + } + } + int mx = 0, cnt = 0; + for (int& cur : ok_sta) for (int& pre : pre_sta[cur]) (dp[lst][cur][pre] > mx) ? (mx = dp[lst][cur][pre], cnt = 1) : (dp[lst][cur][pre] == mx) ? (++cnt) : (0); + printf("%d %d\n", mx, cnt); +} + +int main() +{ + init_popcnt(); + while (scanf("%d%d", &m, &n) != EOF) solve(), clr(); +}