POJ 1160 (interval DP + quadrilateral optimization)
This transfer equation is hard to think about, especially when the solution of a piece of value is intermediate. Dp [I] [j] uses I post offices to cover the minimum values of the first j villages.
There is also the parallelogram optimization of the interval dp. The transfer equation of this question is not "interval DP", so the enumeration state should be reversed (very time-consuming ), in addition, if a post office is used to overwrite the data, the data is dropped from 0, which means the data is not broken.
Compared to the standard interval DP, such as gravel merging and matrix chain multiplication, which is obtained before the required status.
# Include
# Include
# Include
Using namespace std; const int NN = 310; const int INF = 0x7fffffff; int n, m; int s [NN], dp [NN] [NN], w [NN] [NN], p [NN] [NN]; void get_w () // find ~ The minimum distance between building a post office in Village j and {for (int I = 1; I
// Parallelogram Optimization for straight-line stone extraction: # include
# Include
# Include
Using namespace std; const int INF = 1 <30; const int N = 1005; int dp [N] [N]; int p [N] [N]; int sum [N]; int n; int getMinval () {for (int I = 1; I <= n; I ++) {dp [I] [I] = 0; p [I] [I] = I; // The multiplication between yourself and yourself is naturally separated by yourself. } For (int len = 1; len