这道题还是比较简单的费用流,由于w是递增的
实际上,这题数据还可以强一点,比如说分段函数不保证费用递增,
就要加一点技巧了(要保证函数的顺序)
1 const inf=100000007; 2 type node=record 3 next,point,flow,cost:longint; 4 end; 5 var q:array[0..1000010] of longint; 6 edge:array[0..1000010] of node; 7 v:array[0..2010] of boolean; 8 p,time,c,d,pre:array[0..2010] of longint; 9 len,i,j,n,m,t,total,s,w,x:longint; 10 ans:int64; 11 12 procedure add(x,y,f,w:longint); 13 begin 14 inc(len); 15 edge[len].point:=y; 16 edge[len].flow:=f; 17 edge[len].cost:=w; 18 edge[len].next:=p[x]; 19 p[x]:=len; 20 end; 21 22 function spfa:boolean; 23 var i,j,f,r,x,y:longint; 24 begin 25 fillchar(v,sizeof(v),false); 26 v[0]:=true; 27 for i:=1 to t do 28 d[i]:=inf; 29 d[0]:=0; 30 f:=1; 31 r:=1; 32 q[1]:=0; 33 while f<=r do 34 begin 35 x:=q[f]; 36 v[x]:=false; 37 i:=p[x]; 38 while i<>-1 do 39 begin 40 y:=edge[i].point; 41 if edge[i].flow>0 then 42 if d[y]>d[x]+edge[i].cost then 43 begin 44 d[y]:=d[x]+edge[i].cost; 45 pre[y]:=i; 46 time[y]:=x; 47 if not v[y] then 48 begin 49 v[y]:=true; 50 inc(r); 51 q[r]:=y; 52 end; 53 end; 54 i:=edge[i].next; 55 end; 56 inc(f); 57 end; 58 if d[t]=inf then exit(false) else exit(true); 59 end; 60 61 procedure mincost; 62 var i,j,x,y,neck:longint; 63 begin 64 while spfa do 65 begin 66 neck:=inf; 67 i:=t; 68 while i<>0 do 69 begin 70 j:=pre[i]; 71 if neck>edge[j].flow then neck:=edge[j].flow; 72 i:=time[i]; 73 end; 74 i:=t; 75 while i<>0 do 76 begin 77 j:=pre[i]; 78 dec(edge[j].flow,neck); 79 inc(edge[j xor 1].flow,neck); 80 i:=time[i]; 81 end; 82 ans:=ans+neck*d[t]; 83 end; 84 end; 85 86 begin 87 readln(n,m); 88 len:=-1; 89 fillchar(p,sizeof(p),255); 90 for i:=1 to m do 91 begin 92 read(c[i]); 93 add(0,i,c[i],0); 94 add(i,0,0,0); 95 end; 96 for i:=1 to n do 97 begin 98 for j:=1 to m do 99 begin 100 read(x); 101 if x=1 then 102 begin 103 add(j,i+m,c[j],0); 104 add(i+m,j,0,0); 105 end; 106 end; 107 end; 108 t:=n+m+1; 109 for i:=1 to n do 110 begin 111 readln(s); 112 fillchar(time,sizeof(time),0); 113 for j:=1 to s do 114 read(time[j]); 115 for j:=1 to s do 116 begin 117 read(w); 118 add(i+m,t,time[j]-time[j-1],w); 119 add(t,i+m,0,-w); 120 end; 121 read(w); 122 add(i+m,t,inf,w); 123 add(t,i+m,0,-w); 124 end; 125 mincost; 126 writeln(ans); 127 end.