zoj 3363 Another Brick in the...

zoj 3363 Another Brick in the...,第1张

zoj 3363 Another Brick in the...
#include <cstdio>#include <algorithm>#include <cstring>unsigned dp[9][1 << 18];unsigned ans[9][9];void init(const int n) {    const int m = n + 1, mm = (1 << m) - 1;    int a, b, s;    memset(dp, 0, sizeof(dp));    dp[1][(1 << (m + m)) - 2] = 1;    for (int i = 1; i <= 8; ++i) {        for (int j = 0; j < (1 << (m + m)); ++j) { if (dp[i][j] == 0) {     continue; } a = j >> m; b = j & mm; if (b != 0 && b == (b & (         (a & (a << 1)) |         (a & (b << 1)) |          ((a << 1) & (b >> 1))     ))) {     ans[n][i] += dp[i][j]; } if (i == 8) {     continue; } s = (i & 1) ? (1 << m) : (1 << n); for (int c = 1; c < s; ++c) {     if (b == (b & (  (a & (a << 1)) |      (a & c & ~(c << 1)) |  ((a << 1) & (c << 1) & ~c) |      (a & (b << 1)) |       ((a << 1) & (b >> 1))  ))) {         if (i & 1) {  dp[i + 1][(b << n) ^ c] += dp[i][j];         } else {  dp[i + 1][(b << m) ^ (c << 1)] += dp[i][j];         }     } }        }    }}int main() {    int m, n;    for (int i = 1; i <= 8; ++i) {        init(i);    }    while (scanf("%d%d", &m, &n) != EOF) {        printf("%un", ans[m][n]);    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4928335.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存