HDU

HDU - 1400

思路:

轮廓线dp入门题

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 15;
LL dp[2][1<<N], n, m, cur;
void update(int a, int b) {
    if(b & (1<<m))dp[cur][b^(1<<m)] += dp[1-cur][a];
}
int main() {
    while(~ scanf("%d%d", &n, &m) && n && m) {
        if(n < m) swap(n, m);
        mem(dp, 0);
        cur = 0;
        dp[0][(1<<m)-1] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cur ^= 1;
                mem(dp[cur], 0);
                for (int k = 0; k < (1<<m); k++) {
                    update(k, k<<1);
                    if(i && !(k & (1<<m-1))) update(k, (k<<1)^(1<<m)^1);
                    if(j && !(k & 1)) update(k, (k<<1)^3);
                }

            }
        }
        printf("%lld
", dp[cur][(1<<m)-1]);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/widsom/p/9095892.html