Test instructions
There are n toys, to be divided into groups, toys with the same width, but the length of C may be different . Give the order of n toys, any number of consecutive toys can become a group. The cost of the interval [i,j] becomes a group of cost= (J-i+sigma (Ck)-L) 2 and I<=k<=j. Given N and L and the length of each toy, what is the sum of the costs after the question is grouped? (n<=5*104).
Ideas:
Note: The cost is not a straight line function, the total length of each group + the number of toys closer to L better.
Transfer equation: Dp[i]=min (dp[j]+ (sum[i]-sum[j]+i-j+1-l) 2). Sum[i] Represents the sum of the length of the front I piece of toys, 0<j<i, (i-j+1) represents the number of toys in the same group as I.
According to the equation is possible to introduce this problem is to satisfy the decision Monotonicity. The following is a copy of the certificate, slightly modified:
Make f[i]=sum[i]+i, C=1+l, then dp[i]=min (dp[j]+ (f[i]-f[j]-c) 2)
1. proving monotonicity of decisions
Assuming that K decision at State i is superior to J decision, and J<k, then dp[k]+ (f[i]-f[k]-c) 2<=dp[j]+ (f[i]- DP[J]-C) 2.
And for a state T after I, set f[t]=f[i]+v, regardless of the V is how much.
To prove:dp[k]+ (f[t]-f[k]-c) 2<=dp[j]+ (f[t]-f[j]-c) 2
As long as the certificate ( f[t]=f[i]+v ):dp[k]+ (f[i]+v-f[k]-c) 2<=dp[j]+ (f[i]+v-f[j]-c) 2
As long as the card dp[k]+ (f[i]-f[k]-c) 2+2v* (f[i]-f[k]-c) +v2 <= dp[j]+ (f[i]-f[j]-c) 2+2v* (f[i]-f[j]-c) +v2.
As a hypothesis, so long as the certificate: 2v* (f[i]-f[k]-c) <=2v* (f[i]-f[j]-c).
Certificate:f[k]>=f[j](obviously)
Proof complete.
HYSBZ 1010 Toy Packing Toy (decision monotone DP)