凸四边形不等式法则(平行四边形法则)
参考资料:四边形不等式优化讲解(详解)
前提条件:
- \(dp_{i,j}=\max/\min\{dp_{i,k}+dp_{k+1,j}\}+cost_{i,j}\)
- \(cost_{i,j}-cost_{i-1,j}\)单调递增
我们来证明几个性质:
-
令\(i<i+1 \le j < j+1\),则\(cost_{i,j}+cost_{i+1,j+1} \le cost_{i+1,j}+cost_{i,j+1}\)(即满足四边形不等式法则)
证明:对原式进行移项,得\(cost_{i,j}-cost_{i+1,j} \le cost_{i,j+1}-cost_{i+1,j+1}\) -
\(\forall i<i+1 \le j < j+1\),则\(dp_{i,j}+dp_{i+1,j+1} \le dp_{i+1,j}+dp_{i,j+1}\)(既满足四边形不等式法则)
证明:令\(dp_{i+1,j}\)在\(k=x\)时取最小值,\(dp_{i,j+1}\)在\(k=y\)时取最小值。(\(x<y\))
\(dp_{i,j}+dp_{i+1,j+1}=dp_{i,x}+dp_{x+1,j}+cost_{i,j}+dp_{i+1,y}+dp_{y+1,j+1}+cost_{i+1,j+1}\)
\(dp_{i+1,j}+dp_{i,j+1}=dp_{i,x}+dp_{x+1,j+1}+cost_{i,j+1}+dp_{i+1,y}+dp_{y+1,j}+cost_{i+1,j}\)
很显然:\(dp_{i,j}+dp_{i+1,j+1} \le dp_{i+1,j}+dp_{i,j+1}\) -
令\(dp_{i,j}\)在\(best_{i,j}\)处取最优解,则\(best_{i,j-1} \le best_{i,j} \le best_{i+1,j}\)
证明:令\(dp_{i,j-1}\)在\(k=y\)处取最优值,\(\forall x<y有x+1 \le y+1 \le j-1 < j\)
\(dp_{x+1,j-1}+dp_{y+1,j} \le dp_{y+1,j}+dp_{x+1,j} \Rightarrow dp_{i,j-1}(k=x)-dp{i,j-1}(k=y) \le dp_{i,j}(k=x)+dp_{i,j}(k=y)\)
故\(best_{i-1,j} \le best_{i,j} \le best_{i+1,j}\)
所以\(\forall dp_{i,j} = \max/\min\{dp_{i,k}+dp_{k+1,j}\}+cost_{i,j}(best_{i+1,j} \le k \le best_{i,j-1})\)
区间DP的时间复杂度就从\(O(n^3)\)降为\(O(n^2)\)
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。