Solution
好菜啊。。第一次写插头DP。。。
这个
L
型砖块具有特征的就是在之前DP的状态有没有拐过弯。
用
大力分类讨论。
然后这种题打的时候专注一点吧。。
刚开始暴力map,T掉了。。还是得用Hash表。
#include <bits/stdc++.h>
using namespace std;
const int P = 233333;
const int N = 12;
const int M = 111;
const int MOD = 20110520;
typedef pair<int, int> Pairs;
typedef map<int, int>::iterator mit;
int r, c;
char mp[N][M];
struct Map {
int head[P], vis[P];
int pp[505050];
int pnt;
struct edge {
int ori, key, next;
edge(int o = 0, int k = 0, int n = 0): ori(o), key(k), next(n) {}
};
edge G[505050];
int Gcnt, clc;
Map(void) {
clc = 1;
for (int i = 0; i < P; i++) vis[i] = 0;
}
inline void Clear(void) {
Gcnt = pnt = 0; clc++;
}
inline int Head(int x) {
if (vis[x] == clc) return head[x];
else {
vis[x] = clc; return head[x] = 0;
}
}
inline void AddEdge(int from, int ori, int key) {
G[++Gcnt] = edge(ori, key, head[from]); head[from] = Gcnt;
}
inline int &operator [](int x) {
int h = x % P;
for (int i = Head(h); i; i = G[i].next)
if (G[i].ori == x) return G[i].key;
pp[++pnt] = x;
AddEdge(h, x, 0); return G[Gcnt].key;
}
};
Map f[N];
int p[505050];
inline Map &dp(int x, int y) {
return f[y];
}
inline void Add(int &x, int a) {
x = (x + a) % MOD;
}
inline void Update(int x, int y, int nS, int t) {
if (y > c) {
nS ^= (nS >> c >> c) << c << c;
++x; y = 1;
}
Add(dp(x, y)[nS], t);
}
inline void Clear(int x, int y) {
if (y > c) {
++x; y = 1;
}
dp(x, y).Clear();
}
int main(void) {
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
scanf("%d %d", &r, &c);
for (int i = 1; i <= r; i++)
scanf("%s", mp[i] + 1);
if (r < c) {
for (int i = 1; i <= c; i++)
for (int j = i + 1; j <= c; j++)
swap(mp[i][j], mp[j][i]);
swap(r, c);
}
dp(1, 1)[0] = 1;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++) {
Clear(i, j + 1);
for (int k = dp(i, j).pnt; k; k--) p[k] = dp(i, j).pp[k];
for (int k = dp(i, j).pnt; k; k--) {
int S = p[k], t = dp(i, j)[S];
int x = S >> c >> c & 3, y = S & 3;
int nS;
if (mp[i][j] == '*') {
if (x || y) continue;
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
continue;
}
if (x == 0 && y == 0) {
if (j != c) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (2 << (c - 1) << (c - 1)) ^ (2 << c << c);
Update(i, j + 1, nS, t);
}
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (1 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
if (j != c) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (1 << c << c);
Update(i, j + 1, nS, t);
}
}
if (x == 1 && y == 0) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (2 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
if (j != c) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (1 << c << c);
Update(i, j + 1, nS, t);
}
}
if (x == 0 && y == 1) {
if (j != c) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (2 << c << c);
Update(i, j + 1, nS, t);
}
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (1 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
}
if (x == 2 && y == 0) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
if (j != c) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (2 << c << c);
Update(i, j + 1, nS, t);
}
}
if (x == 0 && y == 2) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (2 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
}
if (x == 1 && y == 1) {
nS = (S ^ (x << c << c)) >> 2;
nS = nS ^ (0 << (c - 1) << (c - 1)) ^ (0 << c << c);
Update(i, j + 1, nS, t);
}
}
}
printf("%d\n", dp(r + 1, 1)[0]);
return 0;
}