zoukankan      html  css  js  c++  java
  • bzoj3876

    不高兴的回忆啊啊啊
    当初这种简单题因为自己作死就暴零0了
    这题在OJ上是简单的最小有下界费用流,增广到正费用为止
    因为算的是总时限
    但实际的话似乎要用pacman吃豆豆那题的方法先用dp跑出第一次的增广路再用spfa增广

      1 const inf=420007;
      2 type node=record
      3        cost,flow,next,point:longint;
      4      end;
      5 
      6 var edge:array[0..200010] of node;
      7     p,pre,cur,d:array[0..310] of longint;
      8     q:array[0..1000010] of longint;
      9     v:array[0..310] of boolean;
     10     j,i,n,m,s,t,len,x,y:longint;
     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,x,y,f,r:longint;
     24   begin
     25     f:=1;
     26     r:=1;
     27     d[1]:=0;
     28     for i:=2 to t do
     29       d[i]:=100000007;
     30     fillchar(v,sizeof(v),false);
     31     q[1]:=1;
     32     v[1]:=true;
     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]>edge[i].cost+d[x] then
     43           begin
     44             d[y]:=edge[i].cost+d[x];
     45             pre[y]:=x;
     46             cur[y]:=i;
     47             if not v[y] then
     48             begin
     49               inc(r);
     50               q[r]:=y;
     51               v[y]:=true;
     52             end;
     53           end;
     54         i:=edge[i].next;
     55       end;
     56       inc(f);
     57     end;
     58     if d[t]=100000007 then exit(false) else exit(true);
     59   end;
     60 
     61 function mincost:longint;
     62   var i,j,s:longint;
     63   begin
     64     mincost:=0;
     65     s:=0;
     66     while spfa do
     67     begin
     68       if d[t]>=0 then exit;
     69       i:=t;
     70       while i<>1 do
     71       begin
     72         j:=cur[i];
     73         dec(edge[j].flow);
     74         inc(edge[j xor 1].flow);
     75         i:=pre[i];
     76       end;
     77       mincost:=mincost+d[t];
     78     end;
     79   end;
     80 
     81 begin
     82   readln(n);
     83   fillchar(p,sizeof(p),255);
     84   len:=-1;
     85   t:=n+1;
     86   for i:=1 to n do
     87   begin
     88     read(s);
     89     m:=m+s;
     90     for j:=1 to s do
     91     begin
     92       read(x,y);
     93       add(i,x,1,-inf+y);
     94       add(x,i,0,inf-y);
     95       add(i,x,inf,y);
     96       add(x,i,0,-y);
     97     end;
     98     add(i,t,inf,0);
     99     add(t,i,0,0);
    100   end;
    101   writeln(mincost+m*inf);
    102 end.
    103 
    104  
    View Code
  • 相关阅读:
    ZeroMQ接口函数之 :zmq_msg_move
    ZeroMQ接口函数之 :zmq_msg_init_size
    Missing artifact org.hibernate:hibernate-core:jar:4.3.0.Final
    ezmorph将一种对象转换成另外一种对象
    Avalon Framework
    easymock单元测试跟踪工具
    pngencoder图像转换jar
    Lucene全文检索引擎
    cxf怎样提高webservice性能,及访问速度调优
    待整理-20180625
  • 原文地址:https://www.cnblogs.com/phile/p/4473014.html
Copyright © 2011-2022 走看看