标签:
事实上这道题的原型是1258——关路灯,为什么选了这个呢?
废话,因为题目呗= =
言规正传,觉得这道题扯到看不懂的可以去翻codevs1258,说的挺易懂的
其实就是一道区间dp,比较裸的代码,考虑清楚就好
记录过去和回来的最小安慰时间= =
贴代码
var n,c,i,j,sum:longint; m,w:array[0..1100] of longint; a,l,r:array[0..1005,0..1005] of longint; function min(a,b:longint):longint; begin if a<b then exit(a) else exit(b); end; begin readln(n,c); sum:=0; for i:=1 to n do begin readln(m[i],w[i]); inc(sum,w[i]); end; for i:=1 to n do begin a[i,i]:=sum-w[i]; for j:=i+1 to n do a[i,j]:=a[i,j-1]-w[j]; end; for i:=c+1 to n do begin r[c,i]:=r[c,i-1]+(m[i]-m[i-1])*a[c,i-1]; l[c,i]:=r[c,i]+(m[i]-m[c])*a[c,i]; end; for i:=c-1 downto 1 do begin l[i,c]:=l[i+1,c]+(m[i+1]-m[i])*a[i+1,c]; r[i,c]:=l[i,c]+(m[c]-m[i])*a[i,c]; end; for i:=c-1 downto 1 do for j:=c+1 to n do begin r[i,j]:=min(r[i,j-1]+(m[j]-m[j-1])*a[i,j-1],l[i,j-1]+(m[j]-m[i])*a[i,j-1]); l[i,j]:=min(l[i+1,j]+(m[i+1]-m[i])*a[i+1,j],r[i+1,j]+(m[j]-m[i])*a[i+1,j]); end; writeln(min(l[1,n],r[1,n])); end.
标签:
原文地址:http://www.cnblogs.com/victorslave/p/4805642.html