Blog of RuSun

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

CF348D Turtles

LuoGu: CF348D Turtles

CF: D. Turtles

不重合的两个起点为 $(1, 2), (2, 1)$ ,两个终点为 $(n - 1, m), (n, m - 1)$ 。

根据 LGV 引理,计算 $n = 2$ 的行列式。需要知道每个起点到每个终点的方案数,直接暴力DP即可。

查看代码
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
#include <cstdio>
using namespace std;
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';
if (flag) x = ~x + 1;
}
template <class Type, class ...rest>
void read(Type &x, rest &...y) { read(x), read(y...); }
template <class Type>
void write(Type x)
{
if (x < 0) putchar('-'), x = ~x + 1;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
typedef long long LL;
const int N = 3e3 + 10, mod = 1e9 + 7;
void adj (int &x) { x += x >> 31 & mod; }
int n, m, f[N][N];
bool mp[N][N];
int calc (int sx, int sy, int ex, int ey)
{
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
f[i][j] = 0;
f[sx][sy] = mp[sx][sy];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) if (mp[i][j])
adj(f[i][j] += f[i - 1][j] - mod), adj(f[i][j] += f[i][j - 1] - mod);
return f[ex][ey];
}
int main ()
{
read(n, m);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
{
char c = getchar();
while (c != '.' && c != '#') c = getchar();
mp[i][j] = c == '.';
}
write(((LL)calc(1, 2, n - 1, m) * calc(2, 1, n, m - 1) % mod - (LL)calc(1, 2, n, m - 1) * calc(2, 1, n - 1, m) % mod + mod) % mod);
return 0;
}