CF 553E Kyoya and Train

题目分析

期望\(\text{dp}\)

\(f_{i,j}\)表示在第\(j\)个时刻从\(i\)点出发,到达终点的期望花费。

有转移方程:
\[ f_{x,t}=\min_{(x,y)\in E}(c_{x,y}+\sum_{i=1}^Tp_{y,i}\cdot f_{y,i+t}) \]

如果直接转移,时间复杂度是\(O(n \cdot T^2)\)

考虑如何优化。

冷静分析发现,\(\sum\limits_{i=1}^Tp_{y,i}\cdot f_{y,i+t}\)可以化成卷积形式。

\(g_{y,t}=\sum\limits_{i=1}^Tp_{y,i}\cdot f_{y,i+t}\)

如果我们已知\(f_{y,i}(i\ge t)\),那么我们可以\(O(m\cdot T\cdot \log T)\)算出\(f_{y,i}(i\ge t)\)\(g_{y,t}\)的贡献。

如果我们倒着枚举时间\(t\),边dp边算贡献,每个时间\(t\)会计算贡献\(O(T)\)次,时间复杂度是\(O(m\cdot T^2\cdot \log T)\)

考虑分治\(\text{fft}\)

每次分治区间\([l,r]\),处理完右区间后,统计右区间对左区间的贡献,再处理左区间。

时间复杂度\(O(m\cdot T\cdot \log T)\),可以接受。

有点卡常,需要手写\(\text{complex}\)

猜你喜欢

转载自www.cnblogs.com/Trrui/p/10031821.html