版本比较
题解:AT_abc228_g [ABC228G] Digits on Grid
正文
增加 5 行删除 5 行
9 行未改动1011121314141516161718181920202122232445 行未改动707172737474759 行未改动令 $h_{i,S}$ 表示可能处于列的状态为 $S$,下一步到达数字为 $i$ 的格子,可能到达的行的状态。
可得出转移如下:
$$f_{i,S}\longrightarrow f_{i+1,g_{1,S}/h_{1,S}}$$ $$f_{i,S}\longrightarrow f_{i+1,g_{1,S}/h_{1,S}}$$
$$f_{i,S}\longrightarrow f_{i+1,g_{2,S}/h_{2,S}}$$ $$f_{i,S}\longrightarrow f_{i+1,g_{2,S}/h_{2,S}}$$
$$\cdots$$ $$\cdots$$
$$f_{i,S}\longrightarrow f_{i+1,g_{9,S}/h_{9,S}}$$ $$f_{i,S}\longrightarrow f_{i+1,g_{9,S}/h_{9,S}}$$
对于每一个最终状态,它都唯一对应了一种颜色序列,故可以做到不重复不遗漏地计数。
$h$ 和 $g$ 可以预处理,$f$ 可以依照上式递推,故时间复杂度为 $O\left(HW\left(2^H+2^W\right)+Pn\left(2^H+2^W\right)\right)$,其中 $P=10$。45 行未改动 for (int i = 1; i < (1 << n); i++) ans = (ans + f[1][i]) % mod; cout << ans << endl; return 0;} }```