"Bzoj 1066" [SCOI2007] Lizard

Source: Internet
Author: User

Description

In the grid map of a row C column, there are some highly different pillars, some of which stand on a few lizards, and your task is to get as many lizards as possible to escape the border. The distance of each column in each row is 1, and the lizard's jumping distance is D, that is, the lizard can jump to any one of the columns with a plane distance not exceeding d. The columns are unstable, and each time the lizard jumps, the height of the stone column is reduced by 1 (if it still falls inside the map, the height of the stone column is not changed), and if the column has a height of 1, the lizard disappears after it leaves. Other lizards cannot settle in the future. No two lizards can be found on the same stone column at any one time.

Input

Enter the first behavior three integer r,c,d, which is the size of the map and the maximum jump distance. The following r behavior is the initial state of the carnation, 0 means that there are no columns, and the initial height of the column. The following r behavior is the lizard position, "L" denotes the lizard, "." means no lizards.

Output

The output is only one row, containing an integer, the minimum number of lizards that cannot escape.

Sample Input5 8 2
00000000
02000000
00321100
02000000
00000000
........
........
.. Llll.
........
........Sample Output1HINT

100% data satisfies: 1<=r, c<=20, 1<=d<=4

This is probably the most difficult network flow problem I've ever had (yes, I'm so weak, you hit me)

The x,x ', flow is height, there is a lizard point x with an S edge, a capacity of 1, all can roll the coarse point x ' with the t edge, the capacity INF, so can reach each other point x ', Y edge, capacity inf, run Max Stream

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <iostream>5 using namespacestd;6 Const intinf=10000000, n=1010;7 structee{intTo,next,f;} e[50010];8 inthead[n],q[n*2],map[ -][ -],dis[n];9 intS,t,r,c,d,cnt=1, ans;Ten Chars[ -]; One intSqrintx) {returnx*x;} A   - intwzintXintYintadd) { -     return(X-1) *c+y+r*c*add); the } -   - DoubleDistintX1,intY1,intX2,inty2) { -     returnsqrt (SQR (x1-x2) +SQR (y1-y2)); + } -   + voidInsintUintVintf) { Ae[++cnt].to=v;e[cnt].f=f;e[cnt].next=head[u];head[u]=CNT; ate[++cnt].to=u;e[cnt].f=0; e[cnt].next=head[v];head[v]=CNT; - } -   - intPdintXinty) { -     if(x<=d| | r-x<d| | y<=d| | C-Y&LT;D)return 1; -     return 0; in } -   to BOOLBFs () { +      for(intI=1; i<=t;i++) dis[i]=inf; -     intH=0, t=1, now; theq[1]=s;dis[s]=0; *      while(h!=t) { $now=q[++h];Panax Notoginseng          for(intI=head[now];i;i=E[i].next) { -             intv=e[i].to; the             if(e[i].f&&dis[now]+1<Dis[v]) { +dis[v]=dis[now]+1; A                 if(v==t)return 1; theq[++t]=v; +             } -         } $     } $     if(Dis[t]==inf)return 0;return 1; - } -   the intDinic (intNowintf) { -     if(now==t)returnF;Wuyi     intrest=F; the      for(intI=head[now];i;i=E[i].next) { -         intv=e[i].to; Wu         if(e[i].f&&dis[v]==dis[now]+1){ -             intt=dinic (V,min (REST,E[I].F)); About             if(!t) dis[v]=0; $e[i].f-=T; -e[i^1].f+=T; -rest-=T; -         } A     } +     returnF-rest; the } -   $ intMain () { thescanf"%d%d%d",&r,&c,&d); thes=0, t=2*r*c+1; the      for(intI=1; i<=r;i++){ thescanf"%s", s); -         intL=strlen (s); in          for(intj=0; j<l;j++) map[i][j+1]=s[j]-'0'; the     } the      for(intI=1; i<=r;i++){ Aboutscanf"%s", s); the         intL=strlen (s); the          for(intj=0; j<l;j++){ the             if(s[j]=='L') Ins (S,wz (i,j+1,0),1), ans++; +         } -     } the      for(intI=1; i<=r;i++)Bayi          for(intj=1; j<=c;j++) the             if(Map[i][j]) ins (wz (I,J,0), WZ (I,j,1), map[i][j]); the       -      for(intx1=1; x1<=r;x1++) -          for(inty1=1; y1<=c;y1++){ the             if(!map[x1][y1])Continue; the              for(intX2=1; x2<=r;x2++) the                  for(intY2=1; y2<=c;y2++){ the                     if(X1==x2&&y1==y2)Continue;  -                     if(Map[x1][y1]&&map[x2][y2]&&dist (X1,y1,x2,y2) <=d) { theIns (wz (X1,y1,1), WZ (X2,y2,0), INF); theIns (wz (X2,y2,1), WZ (X1,y1,0), INF); the                     }94                 } the             } the       the      for(intI=1; i<=r;i++)98          for(intj=1; j<=c;j++) About             if(PD (I,J)) Ins (wz (I,J,1), T,inf);  -      while(BFS ())101ans-=dinic (s,inf);102printf"%d", ans);103}

"Bzoj 1066" [SCOI2007] Lizard

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.