轮廓线DP。。。白书例题。。思路具体看白书。。。这里的代码和白书差不多。。。
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 5005
#define maxm 300006
#define eps 1e-10
#define mod 1315423911
#define INF 1e9
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid
#define rson o<<1 | 1, mid+1, R
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;
LL dp[2][maxn];
int n, m, cur;
inline void updata(int a, int b)
{
if(b & (1 << m)) dp[cur][b ^ (1 << m)] += dp[cur ^ 1][a];
}
void work(void)
{
if(n < m) swap(n, m);
memset(dp, 0, sizeof dp);
cur = 0;
dp[0][(1<<m)-1] = 1;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
cur ^= 1;
memset(dp[cur], 0, sizeof dp[cur]);
for(int k = 0; k < (1 << m); k++) {
updata(k, k << 1);
if(i && !(k & (1 << (m-1)))) updata(k, (k << 1) ^ (1 << m) ^ 1);
if(j && !(k & 1)) updata(k, (k << 1) ^ 3);
}
}
}
printf("%lld\n", dp[cur][(1 << m) - 1]);
}
int main(void)
{
while(scanf("%d%d", &n, &m)!=EOF) work();
return 0;
}