链接
Description
\(n \times m\) 的网格(图上有一些点不能走),有两个鳖均从 \((1,1)\) 出发,目标为 \((n,m)\),每次移动只能向下或向右走一格(只能走到没被禁用的方格),两个鳖的路径不能再除起点和终点的方格处相交,问:两个鳖走的路径的方案数。(注意:两个鳖一模一样)。
\(1 \le n,m \le 3000\)。
Solution
容斥 \(\rm dp\)。考虑两个鳖走的方案的形态,只有可能是第一个鳖从 \((1,1) \to (1,2) \to \dots \to (n-1, m) \to (n,m)\),另一个鳖走 \((1,1) \to (2,1) \to \dots \to (n,m-1) \to (n,m)\)。
\[\begin{tikzpicture}\draw[step=1cm,gray,very thin,scale=0.8](0,0) grid (4,4);
\end{tikzpicture}
\]