QOJ.ac

QOJ

حد الوقت: 3 s حد الذاكرة: 512 MB مجموع النقاط: 100

#833. 細胞阻擋

الإحصائيات

給定一個 $n \times m$ 的網格,其中一些格子已經被阻擋。

你需要找出有多少種方法可以再阻擋兩個不同的空閒格子,使得從 $(1, 1)$ 到 $(n, m)$ 不再存在僅透過向右或向下移動且只經過空閒格子的路徑。

注意,阻擋 $(1, 1)$ 和 $(n, m)$ 是被允許的。這些格子也可能在初始狀態下就已經被阻擋。

輸入格式

第一行包含兩個整數 $n$ 和 $m$ ($1 \le n, m \le 3000$):網格的列數與行數。 接下來的 $n$ 行,每行包含 $m$ 個字元,其中第 $i$ 行的第 $j$ 個字元若為 '.' 表示格子 $(i, j)$ 是空閒的,若為 '*' 則表示該格子已被阻擋。

輸出格式

輸出一個整數:阻擋兩個格子後,使得從 $(1, 1)$ 到 $(n, m)$ 不再存在僅透過向右或向下移動且只經過空閒格子的路徑的方法數。

範例

輸入 1

3 3
...
...
...

輸出 1

17

輸入 2

3 3
.**
.*.
...

輸出 2

15

輸入 3

3 4
****
....
****

輸出 3

6

說明

在第一個範例中,如果你阻擋了 $(1, 1)$ 或 $(3, 3)$ 以及任何其他格子,將不會有合法的路徑。這類方法數為 $8 + 8 - 1$。 此外,如果你阻擋了 $((1, 2)$ 和 $(2, 1))$ 或 $((3, 2)$ 和 $(2, 3))$,也不會有合法的路徑,因此答案為 $8 + 8 - 1 + 2 = 17$。

在第二個範例中,如果你阻擋任意兩個格子,都不會有路徑存在,因此答案為 $\binom{6}{2} = 15$。

在第三個範例中,初始狀態下就沒有從 $(1, 1)$ 到 $(n, m)$ 的路徑,因此在阻擋任意兩個格子後,依然不會有路徑,所以答案為 $\binom{4}{2} = 6$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1627EditorialOpenNew Editorial for Problem #833louyuxuan2026-04-26 21:47:26View
#602Editorial Open集训队作业 解题报告 by 祁沐笛Qingyu2026-01-02 22:56:38 Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.