Blog of RuSun

\begin {array}{c} \mathfrak {One Problem Is Difficult} \\\\ \mathfrak {Because You Don't Know} \\\\ \mathfrak {Why It Is Diffucult} \end {array}

P4111 [HEOI2015]小 Z 的房间

P4111 [HEOI2015]小 Z 的房间

板子题。

注意一个坑点,只把合法的点算入编号,否则不合法的点没有边直接使得答案为 $0$ 。

查看代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
template <class Type>
void read(Type &x)
{
char c;
bool flag = false;
while ((c = getchar()) < '0' || c > '9')
c == '-' && (flag = true);
x = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + c - '0';
flag && (x = ~x + 1);
}
template <class Type>
void write(Type x)
{
x < 0 && (putchar('-'), x = ~x + 1);
x > 9 && (write(x / 10), 0);
putchar(x % 10 + '0');
}
const int N = 90, M = 10, mod = 1e9, dx[] = {1, 0}, dy[] = {0, 1};
int n, m, tot, A[N][N], id[M][M];
int del ()
{
int res = 1;
for (int i = 1; i <= tot; i++)
for (int j = i + 1; j <= tot; j++)
{
while (A[i][i])
{
int t = A[j][i] / A[i][i];
for (int k = i; k <= tot; k++)
(A[j][k] -= (LL)t * A[i][k] % mod) %= mod;
swap(A[i], A[j]);
res *= -1;
}
swap(A[i], A[j]);
res *= -1;
}
for (int i = 1; i <= tot; i++)
res = (LL)res * A[i][i] % mod;
return res;
}
bool inside (int a, int b)
{
return a > 0 && b > 0 && a <= n && b <= m;
}
int main ()
{
read(n), read(m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
char c = getchar();
while (c != '.' && c != '*')
c = getchar();
c == '.' && (id[i][j] = ++tot);
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
for (int k = 0; id[i][j] && k < 2; k++)
{
int nx = i + dx[k], ny = j + dy[k];
if (!inside(nx, ny) || !id[nx][ny])
continue;
A[id[i][j]][id[i][j]]++, A[id[nx][ny]][id[nx][ny]]++, A[id[i][j]][id[nx][ny]]--, A[id[nx][ny]][id[i][j]]--;
}
tot--;
write((del() + mod) % mod);
return 0;
}