I have not done any questions for a long time, and I cannot write any dynamic equations.
Refer to iwtwiioi, which indicates that the interval seems more convenient.
If f [I, j] indicates that I has not been sold to J
F [I, j] = max (F [I + 1, J] + V [I] * t, F [I, j-1] + V [J] * t) (why is it better to use the push method ..)
1 /************************************************************** 2 Problem: 1652 3 User: rausen 4 Language: Pascal 5 Result: Accepted 6 Time:136 ms 7 Memory:24852 kb 8 ****************************************************************/ 9 10 uses math;11 12 var13 n, k, i, j, t : longint;14 f : array[0..2500, 0..2500] of longint;15 v : array[0..2500] of longint;16 17 begin18 readln(n);19 for i := 1 to n do20 read(v[i]);21 for k := 1 to n do begin22 t := n - k + 1;23 for i := 1 to t do begin24 j := i + k - 1;25 f[i, j] := max(f[i + 1, j] + t * v[i], f[i, j - 1] + t * v[j]);26 end;27 end;28 writeln(f[1, n]);29 end.
View code
Bzoj1652 [usaco 2006 Feb] treats for the cows