Quadrilateral dynamic programming optimization of inequality

Quadrilateral inequality

Provided function \ (w (x, y) \) is defined in \ (the Z \) function on, if for any \ (A, B, C, D \ in the Z \) , where \ (a \ leq b \ C Leq \ Leq D \) , are \ (W (A, D) + W (B, C) \ GE W (A, C) + W (B, D) \) , a function called \ (W \ ) to meet the quadrangle inequality

inference:

Provided function \ (w (x, y) \) is defined in \ (the Z \) function on, if for any \ (A, B \ in the Z \) , where \ (A <B \) , are \ (W (A, B +. 1) + W (A +. 1, B) \ GE W (A, B) + W (A +. 1, B +. 1) \) , the function \ (W \) satisfies quadrilateral inequality

prove:

For \ (A <C \) , there are:
\ [W (A, C +. 1) + W (A +. 1, C) \ GE W (A, C) + W (A +. 1, C +. 1) \ ]
for \ (A +. 1 <C \) , there are:
\ [W (A +. 1, C +. 1) + W (A + 2, C) \ GE W (A +. 1, C) + W (A + 2, c + 1) \]
two equations are added to obtain:
\ [W (A, C +. 1) + W (+. 1 A, C) + W (A +. 1, C +. 1) + W (A + 2, c) \ ge w (
a, c) + w (a + 1, c + 1) \\ + w (a + 1, c) + w (a + 2, c + 1) \] order was:
\ [w (a, c +
1) + w (a + 2, c) \ ge w (a, c) + w (a + 2, c + 1) \] and so on, for any \ (A \ B Leq \ Leq C \) , there are:
\ [W (A, C +. 1) + W (B, C) \ GE W (A, C) + W (B, C +. 1) \]
(i.e., where with \ (B \) instead of \ (A + 2 \) , since \ (. 1 + A <C \) , so \ (B \ Leq C \) )

Similarly, for any \ (A \ B Leq \ Leq C \ Leq D \) , there are:
\ [W (A, D) + W (B, C) \ GE W (A, C) + W (B, d) \]

Theorem 1

For any \ (A, B, C, D \ in the Z \) , if the function \ (W \) satisfies quadrilateral inequality, and \ (W (A, D) \ GE W (B, C) \) , then the function \ (F \) satisfies quadrilateral inequality, where \ (F \) satisfies:
\ [F (X, Y) = min (F (X, Z) + F (Z +. 1, Y) + W (X, Y ) | X \ Leq Z <Y) \]
(particularly, we let \ (F (X, Y) = W (X, Y) = 0 \) )

prove:

When \ (x + 1 = y \ ) , we have:
\ [F (X, Y +. 1) + F (X +. 1, Y) = F (X, X + 2) + F (X +. 1, x + 1) = f (x
, x + 2) \] If \ (f (x, x + 2) \) is the optimal decision is \ (. 1 + X \) , then:
\ [F (X, X +2) = f (x, x + 1) + f (x + 2, x + 2) + w (x, x + 2) = w (x, x + 1) + w (x, x + 2) \]
obviously
\ [w (x, x +
1) + w (x, x + 2) \ ge w (x, x + 1) + w (x + 1, x + 2) \] If \ (F ( x, x + 2) \) is the optimal decision is \ (X \) , then:
\ [F (X, X + 2) = F (X, X) + F (. 1 + X, X + 2) + w (x, x + 2)
= w (x + 1, x + 2) + w (x, x + 2) \] obviously
\ [w (x + 1, x + 2) + w (x, x + 2) \ ge w (x +
1, x + 2) + w (x, x + 1) \] and
\ [w (x, x + 1) + w (x + 1, x + 2) = f ( x, x + 1) + f
(x + 1, x + 2) = f (x, y) + f (x + 1, y + 1) \] Therefore, when \ (x + 1 = y \ ) , the we get:
\ [F (X, Y +. 1) + F (. 1 + X, Y) \ GE F (X, Y) + F (. 1 + X, + Y. 1) \]
i.e. inequality quadrangular case.

Next, we use mathematical induction

Assume that when \ (yx <k \) , the quadrilateral inequality.

We now consider the \ (yx = k \) case

Order \ (f (x, y + 1) \) to \ (A \) is the optimal decision, \ (F (. 1 + X, Y) \) to \ (B \) for the optimal decision.

May assume \ (x + 1 \ leq a \ leq b \)

Easy to get:
\ [F (X, Y +. 1) + F (X +. 1, Y) = F (X, A) + F (A +. 1, Y +. 1) + W (X, Y +. 1) \ \ + f (x + 1,
b) + f (b + 1, y) + w (x + 1, y) \] to \ (f (x, y) \) and \ (f (x + 1, 1 + the y-) \) , due to the \ (A \) , \ (b \) is not necessarily the optimal decision, so we have:
\ [f (the X-, the y-) + f (the X-+ 1, the y-+ 1) \ le f (x, a) + f (a + 1, y) + w (x, y) \\ + f (x + 1, b) + f (b + 1, y + 1) + w (x + 1, y + 1) \]
since \ (W \) satisfies quadrilateral inequality, so:
\ [W (X, Y +. 1) + W (X +. 1, Y) \ GE W (X, Y) + W ( x + 1, y + 1)
\] inductive hypothesis, we have:
\ [F (A +. 1, Y +. 1) + F (B +. 1, Y) \ GE F (A +. 1, Y) + F (b + 1, y + 1
) \] so we have:
\ [F (X, Y +. 1) + F (X +. 1, Y) \ GE F (X, Y) + (X +. 1, Y + 1) \]

Theorem 2:

For any \ (A, B, C, D \ in the Z \) , if the function \ (W \) satisfies quadrilateral inequality, and the function \ (F \) satisfies:
\ [F (X, Y) = min (F ( X, Z) + F (Z +. 1, Y) + W (X, Y) | X \ Leq Z <Y) \]
(particularly, we let \ (f (x, y) = w (x, y ) = 0 \) )

Note \ (P (x, y) \) is the Order \ (f (x, y) \) takes a minimum value to \ (K \) values. If the function \ (F \) satisfies quadrilateral inequality, then for any \ (X \) , \ (Y \) , we have:
\ [P (X, Y-. 1) \ Leq P (X, Y) \ Leq P (x + 1, y) \
] proof:

Note \ (P = P (I, J) \) .

For any \ (X <K \ Leq P \) , the inequality obtained by the quadrilateral:
\ [F (X, T) + F (X +. 1, K) \ GE F (X, K) + F (X +. 1 , t) \]
transposing obtained:
\ [F (X +. 1, K) -f (. 1 + X, T) \ GE F (X, K) -f (X, t) \]
Since \ (P \ ) for the optimal decision, so we have:
\ [f (the X-, k) + f (k + 1, the y-) \ GE f (the X-, the p-) + f (the p-+ 1, the y-) \]
so:
\ [ \ begin {array} {lcr} (f (x + 1, k) + f (k + 1, y) + w (x + 1, y)) - (f (x + 1, p) + f (p + 1, y) + w ( x + 1, y)) \\ = (f (x + 1, k) -f (x + 1, p)) + (f (k + 1, y) -f ( p + 1, y)) \\ \ ge (f (x, k) -f (x, p)) + (f (k + 1, y) -f (p + 1, y)) \\ = ( f (x, k) + f
(k + 1, y)) - (f (x, p) + f (p + 1, y)) \\ \ ge 0 \ end {array} \] this means, for \ (f (x + 1, y) \) any decision \ (K \ Leq P \) , \ (P \) better than \ (K \) and more preferably (including equal to)

So
\ [P (x + 1,
y) \ ge P (x, y) \] same reason
\ [P (x, y-
1) \ leq P (x, y) \] so
\ [P ( x, y-1) \ leq P (x, y) \ leq P (x + 1, y)) \]

example

1. [NOI1995] combined gravel

There are \ (n-\) stack stones (cyclic), can only be combined into a pile adjacent piles, stones each score is the sum of the two teams, seeking the maximum and minimum score Score

Obviously, this question is the interval dp.

Order \ (dp [i] [j ] \) represents \ (I \) to \ (J \) minimum combined between the stones (maximum Similarly), then we can easily lists the state transition equation is : \
[DP [I] [J] = max (DP [I] [J], DP [I] [K] + DP [K +. 1] [J] + D (I, J) | I \ Leq K <j) \]
where \ (d (i, j) \) represents \ (I \) to \ (J \) number between stones

When the problem is the minimum that we can use to optimize the quadrangle inequality. In this case, \ (DP [I] [J] \) , we only need interval \ ([P [x] [ y-1], P [x + 1] [y]] \) enumeration \ ( K \) to the time complexity is \ (O (n ^ 2) \)

(Note: maximum is not monotone, the inequality can not be optimized quadrilateral)

Code:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1005;
int dp[maxn][maxn];
int dp2[maxn][maxn];
int n;
int a[maxn];
int sum[maxn];
int p[maxn][maxn];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i+n]=a[i];
    for(int i=1;i<=2*n;i++) sum[i]=sum[i-1]+a[i],p[i][i]=i;
    for(int i=n<<1;i>=1;i--)
        for(int j=i+1;j<=n<<1;j++){
            dp[i][j]=0x3f3f3f3f;
            for(int k=p[i][j-1];k<=p[i+1][j];k++){
                if(dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]<dp[i][j]){
                    dp[i][j]=dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1];
                    p[i][j]=k;
                }else if(dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1]==dp[i][j])
                    p[i][j]=max(p[i][j],k);
            }
        }
    for(int len=2;len<=n;len++){  
        for(int i=1;i<=n*2;i++){  
            int j=i+len-1;
            if(j>2*n) break;
            for(int k=i;k<j;k++){  
                dp2[i][j]=max(dp2[i][j],dp2[i][k]+dp2[k+1][j]+sum[j]-sum[i-1]);    
            }  
        }  
    }  
    int ans=0x3f3f3f3f;
    int ans2=0;
    for(int i=1;i<=n;i++) ans=min(ans,dp[i][i+n-1]);
    for(int i=1;i<=n;i++) ans2=max(ans2,dp2[i][i+n-1]); 
    printf("%d\n%d\n",ans,ans2);
    return 0;
}

Guess you like

Origin www.cnblogs.com/ybwowen/p/11116654.html