1475: Check number of squares

Source: Internet
Author: User

1475: Check count time limit:5 Sec Memory limit:64 MB
submit:578 solved:309
[Submit] [Status] [Discuss] Description in a n*n square, each lattice has a positive integer. Take out a number of the number, so that any two out of the lattice has no common side, and the sum of the number taken out as large as possible. Input the first row a number n; (n<=30) the next n rows each row n number describes a matrix output only one number, that is, the largest and the sample Input2
1 2
3 5

Sample Output6
HINT Source

Puzzle: Another network flow = =, it seems to learn a new model of the building-the separation of two blocks of the two ends, respectively, and the source and sink connected, and then the middle of the conflict directly with each other (for example, adjacent to the subject) connected to the Infinity edge, and then the network flow and then use the sum cut = =, and then Feel the network flow this thing more learn more magical qaq?
1/**************************************************************2Problem:14753 User:hansbug4 language:pascal5 result:accepted6Time:304Ms7Memory:612KB8****************************************************************/9  Ten type OnePoint=^node; ANode=Record - G,w:longint; - Anti,next:point; the     End; - var - I,j,k,l,m,n,s,t,flow:longint; -A,e:Array[0..10000] ofPoint ; +B,c,d:Array[0..10000] ofLongint; - functionmin (x,y:longint): Longint; +          begin A               ifX<y ThenMin:=xElsemin:=y; at          End; - procedureAdd (x,y,z:longint); -           varP:point; -           begin -New (p);p ^.g:=y;p^.w:=z;p^.next:=a[x];a[x]:=p; -New (p);p ^.g:=x;p^.w:=0;p ^.next:=a[y];a[y]:=p; ina[x]^.anti:=a[y];a[y]^.anti:=A[x]; -           End; to functionSpfa:boolean; +          varF,r,i:longint;p:point; -           begin the                 forI:=s toT Doc[i]:=Maxlongint; *f:=1; r:=2;d [1]:=s;c[s]:=0; $                 whileF<r DoPanax Notoginseng                      begin -p:=A[d[f]]; the                            whileP<>Nil  Do +                                 begin A                                      if(p^.w<>0) and(C[p^.g]=maxlongint) Then the                                         begin +e[p^.g]:=p; -c[p^.g]:=c[d[f]]+1; $d[r]:=P^.g;inc (r); $                                         End; -p:=P^.next; -                                 End; the Inc (f); -                      End;WuyiExit (c[t]<>maxlongint); the           End; - proceduredeal; Wu           begin -i:=t;l:=Maxlongint; About                 whileI<>s Do $                      begin -l:=min (e[i]^.w,l); -i:=e[i]^.anti^.g; -                      End; ADec (flow,l); i:=T; +                 whileI<>s Do the                      begin -                           ifE[i]^.w<>maxlongint ThenDec (e[i]^.w,l); $                           ifE[i]^.anti^.w<>maxlongint ThenInc (E[I]^.ANTI^.W,L); thei:=e[i]^.anti^.g; the                      End; the           End; the begin -READLN (n); flow:=0; s:=1; t:=n*n+2; in       fori:=1  ton*n+2  Doa[i]:=Nil; the       fori:=1  toN Do the           forj:=1  toN Do About              begin the read (k); Inc (FLOW,K); the                   ifOdd (I+j) ThenAdd1, (I-1) *n+j+1KElseAdd (I-1) *n+j+1, n*n+2, k); the                   ifOdd (I+j) Then +                      begin -                           ifI>1  ThenAdd (I-1) *n+j+1, (I-2) *n+j+1, maxlongint); the                           ifI<n ThenAdd (I-1) *n+j+1, (i) *n+j+1, maxlongint);Bayi                           ifJ>1  ThenAdd (I-1) *n+j+1, (I-1) *n+j,maxlongint); the                           ifJ<n ThenAdd (I-1) *n+j+1, (I-1) *n+j+2, maxlongint); the                      End; -                   ifJ=n ThenReadln; -              End; the       whileSpfa Dodeal; the writeln (flow); the Readln; the End.

1475: Check number of squares

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.