bzoj1001 [BeiJing2006] Wolf catches rabbits

Source: Internet
Author: User

1001: [BeiJing2006] wolf catch rabbit time limit:15 Sec Memory limit:162 MB
submit:19687 solved:4870
[Submit] [Status] [Discuss] Description now children favorite "pleasant goat and ash too wolf", saying that the wolf catch the sheep, but the rabbit is still more in line, and now the rabbit is still more stupid, they only two nest, now you as the Wolf King, facing the following a grid of terrain:

The upper-left corner is (n,m) and the lower-right corner is (n=4,m=5). There are three types of roads 1: (x, y) <==> (x+1,y) 2: (x, y) <==> (x,y+1) 3: (x, y) <==> (x+ 1,Y+1) The weight on the road indicates the maximum number of rabbits that can be passed on this road, and the road is non-direction. The upper-left and lower-right corners of the rabbit's two nests, at the beginning of all the rabbits gathered in the upper left corner of the nest, now they have to go to the lower right solution (n,m) in the nest, The Wolf King began to ambush the rabbits. Of course, for the sake of insurance, if a road up to the number of rabbits passed K, the Wolf King needs to arrange the same number of K wolf, in order to completely block the road, you need to help the Wolf King to arrange an ambush plan, so that the rabbit clean sweep under the premise of the number of wolves involved in the Because the wolf also to find pleasant sheep and sheep trouble. Input first behavior n,m. Represents the size of the mesh, n,m are less than or equal to 1000. Next, the first part of the three parts is a total of N rows, each line M-1 number, representing the weight of the transverse road. The second part of the total N-1 line, the number of M per row, indicating the weight of the longitudinal road. The third part of the total N-1 line, the number of M-1 per row, indicating the weighted value of the oblique road. Input file guaranteed not to exceed 10MOutput

Outputs an integer that represents the minimum number of wolves involved in an ambush.

Sample Input3 4
5 6 4
4 3 1
7 5 3
5 6 7 8
8 7 6 5
5 5 5
6 6 6Sample Output - SolvingFloor Plan Maximum flow ... Dong Zhou The paper is very clear ... Put the code on it ...
1/**************************************************************2Problem:10013User:10909007154 language:pascal5 result:accepted6Time:7744Ms7Memory:103760KB8****************************************************************/9  Ten  Programj01; One Constmaxn=2000086; A varB:Array[0.. +,0.. +,0..1] ofLongint; -Q,next,data:Array[0..6000086] ofLongint; -Dis,head,l:Array[0.. MAXN] ofLongint; theInlArray[0.. MAXN] ofBoolean; - N,m,x,i,j,tt,tot:longint; -   - procedureAdd (u,v,w:longint); + begin - Inc (TT); +q[tt]:=v; Anext[tt]:=Head[u]; athead[u]:=tt; -data[tt]:=W; - End; -   - procedureSPFA; - varH,tail,i,j:longint; in begin - Fillchar (dis,sizeof (DIS), $3f); toFillchar (Inl,sizeof (INL),0); +dis[0]:=0; h:=0; tail:=1; l[1]:=0; inl[0]:=true; -    whileH<>tail Do the   begin *Inc (H);ifH>maxn Thenh:=1; $i:=L[h];Panax Notoginsengj:=Head[i]; -      whileJ>0  Do the     begin +       ifDIS[I]+DATA[J]&LT;DIS[Q[J]] Then A       begin thedis[q[j]]:=dis[i]+Data[j]; +         ifInl[q[j]]=false Then -         begin $Inc (tail);ifTail>maxn Thentail:=1; $l[tail]:=Q[j]; -inl[q[j]]:=true; -         End; the       End; -j:=Next[j];Wuyi     End; theinl[i]:=false; -   End; Wu End; -   About begin $ readln (n,m); -tot:=0; -    fori:=1  toN-1  Do -      forj:=1  toM-1  Do A     begin + Inc (TOT); theB[i,j,0]:=tot; - Inc (TOT); $B[i,j,1]:=tot; the     End; the Inc (TOT); theFillchar (Head,sizeof (head),0); thett:=0; -    fori:=1  toN Do in      forj:=1  toM-1  Do the     begin the read (x); About       ifI=1  ThenAdd (B[i,j,1],tot,x); the       ifI=n Then theAdd0, b[i-1J0],x); the       if(i<>1) and(i<>n) Then +       begin -Add (B[i,j,1],b[i-1J0],x); theAdd (b[i-1J0],b[i,j,1],x);Bayi       End; the     End; the    fori:=1  toN-1  Do -      forj:=1  toM Do -     begin the read (x); the       ifj=1  Then theAdd0, B[i,j,0],x); the       ifJ=m ThenAdd (b[i,j-1,1],tot,x); -       if(j<>1) and(j<>m) Then the       begin theAdd (B[i,j,0],b[i,j-1,1],x); theAdd (b[i,j-1,1],b[i,j,0],x);94       End; the     End; the    fori:=1  toN-1  Do the      forj:=1  toM-1  Do98     begin About read (x); -Add (B[i,j,0],b[i,j,1],x);101Add (B[i,j,1],b[i,j,0],x);102     End;103 SPFA;104 Writeln (Dis[tot]); the End.106 
View Code

bzoj1001 [BeiJing2006] wolf catch rabbit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.