luogu P4056 [JSOI2009]火星藏宝图
作者:互联网
题面传送门
显然这道题有定义\(dp_i\)表示到\(i\)点的最大价值,\(dp\)式\(dp_{i}=\max\limits_{j=1}^{i-1}{dp_j-(x_i-x_j)^2-(y_i-y_j)^2+w_i}\)这样的\(dp\)是\(O(n^2)\)的
考虑怎么优化,显然一列中只有最下面的列转移更优,这样复杂度变成\(O(nm)\)
这个亚子似乎可以斜优,展开试试:
\(dp_{i}=dp_{j}+w_i-(x_i^2-2x_ix_j+x_j^2+y_i^2+y_j^2-2y_iy_j)\)
设\(k<j\)且\(k\)劣于\(j\)
则\(dp_k+w_i-(x_i^2-2x_ix_k+x_k^2+y_i^2+y_k^2-2y_iy_k)<dp_{j}+w_i-(x_i^2-2x_ix_j+x_j^2+y_i^2+y_j^2-2y_iy_j)\)
\(dp_k+2x_ix_k-x_k^2+2y_iy_k-y_k^2<dp_j+2x_ix_j-x_j^2+2y_iy_j-y_j^2\)
标签:iy,ix,luogu,2x,2y,藏宝图,P4056,dp 来源: https://www.cnblogs.com/275307894a/p/14220661.html