Skip to content

Commit

Permalink
11.8
Browse files Browse the repository at this point in the history
  • Loading branch information
nalemy committed Nov 8, 2023
1 parent 2a1f880 commit 72a047b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
1 change: 1 addition & 0 deletions _config.icarus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ widgets:
吃人的大嘴龙: https://www.slongod.top
凌给老师: https://llingy.top
玩原神的: https://www.cnblogs.com/xlpg-0713
nma: http://www.nightmarealita.top
# Categories widget configurations
-
# Where should the widget be placed, left sidebar or right sidebar
Expand Down
12 changes: 0 additions & 12 deletions source/_data/friends.json

This file was deleted.

22 changes: 22 additions & 0 deletions source/_posts/CF1662C.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,26 @@ categories:
- 题目
date: 2023-11-07 21:20:44
tags:
- 矩阵
---
如果没有不能相邻两次走同一条边的限制,可以直接矩阵快速幂。对于这样的限制,整体地考虑所有路径,进行容斥亦不现实。

所以回归矩阵乘法做图上路径计数的本质——动态规划。

设 $f_t(i,j)$ 为 $i\to j$ 长为 $t$,且不走回头路的路径数量,那么对于 $t\ge3$ 有递推式

$$ f_t(i,j)=\sum_k f_{t-1}(i,k)f(k,j)-(d_j-1)f_{t-2}(i,j) $$

其中 $d_i$ 等于 $i$ 的度。那么令矩阵 $G_t$ 第 $i$ 行第 $j$ 列为 $f_t(i,j)$,$G_1=G$ 即为原图邻接矩阵,上式等同于

$$ G_t=G_{t-1}G-(D-I)G_{t-2} $$

其中 $D=\mathrm{diag}(d_1,d_2,\cdots,d_n)$。不难发现上式可以矩阵加速:

$$
\begin{bmatrix}0&1\\I-D&G\end{bmatrix}
\begin{bmatrix}G_{t-2}\\G_{t-1}\end{bmatrix}
=\begin{bmatrix}G_{t-1}\\G\end{bmatrix}
$$

矩阵套矩阵,喵喵题。
4 changes: 0 additions & 4 deletions source/friends/index.md

This file was deleted.

0 comments on commit 72a047b

Please sign in to comment.