蒟蒻许久没做题了,然后连动规方程都写不出了。
参照iwtwiioi大神,这样表示区间貌似更方便。
令f[i, j]表示i到j还没卖出去,则
f[i, j] = max(f[i + 1, j] + v[i] * T, f[i, j - 1] + v[j] * T) (←这样用推的方式更好想一点。。)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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 var 13 n, k, i, j, t : longint; 14 f : array[0..2500, 0..2500] of longint; 15 v : array[0..2500] of longint; 16 17 begin 18 readln(n); 19 for i := 1 to n do 20 read(v[i]); 21 for k := 1 to n do begin 22 t := n - k + 1; 23 for i := 1 to t do begin 24 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.
By Xs酱~ 转载请说明
博客地址:http://www.cnblogs.com/rausen