Bzoj 1565: [NOI2009] Plants vs Zombies

Source: Internet
Author: User

1565: [NOI2009] Plants vs Zombies time limit:10 Sec Memory limit:64 MB
submit:2317 solved:1071
[Submit] [Status] [Discuss] The descriptioninputoutput contains only an integer that represents the maximum energy income that can be obtained. Note that you can also choose not to do any attacks so that the energy income is 0. Sample Input3 2
10 0
20 0
-10 0
-5 1 0 0
100 1 2 1
100 0
Sample Output25
HINT

In the sample, the plant p1,1 can attack position (0,0), P2, 0 can attack position (2,1).
A scheme for, first attack p1,1, p0,1, at this time can attack p0,0. The total energy gain is (-5) +20+10 = 25. Note that the location (2,1) is protected by plant p2,0, so it is not possible to attack any plant in line 2nd.
"Approximate data size"
About 20% of the data meet 1≤n, m≤5;
About 40% of the data meet 1≤n, m≤10;
About 100% of the data meets 1≤n≤20,1≤m≤30,-10000≤score≤10000.

SOURCE Analysis:

See this problem feel cordial, this is not the biggest right to close the sub-chart ... The protected point is protected by its point-of-contact, then the bare maximum-weight-closed sub-graph ...

But I can't find a sample ... TAT ... Because there are rings ...

So we have to delete the point of the ring, and if the point on the ring is not selectable, then the point pointing at it cannot be selected ... What to do? Topological sort?

But the topological sort can only judge if there is no ring, cannot judge whether the point is on the ring ... For example, the following picture ...

But it's a coincidence that our chart is that all points pointing to the ring are not selectable ... So reverse all sides ... Topological sort unreachable points are points that need to be deleted ... (WA had a long qaq ... Thank Lmy ...)

Code:
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5#include <queue>6 //by Neighthorn7 #defineINF 0x7fffffff8 using namespacestd;9  Ten Const intmaxn= the+5, maxm=2000000+5; One   A intN,M,S,T,CNT,ANS,HD[MAXN],FL[MAXM],inch[MAXN],TO[MAXM],NXT[MAXM],POS[MAXN],VAL[MAXN],VIS[MAXN],MP[MAXN][MAXN]; -   -InlineBOOLBFsvoid){ thememset (pos,-1,sizeof(POS)); -     intHead=0, tail=0, Q[MAXN]; -q[0]=s,pos[s]=0; -      while(head<=tail) { +         inttop=q[head++]; -          for(inti=hd[top];i!=-1; i=Nxt[i]) +             if(pos[to[i]]==-1&&Fl[i]) Apos[to[i]]=pos[top]+1, q[++tail]=To[i]; at     } -     returnpos[t]!=-1; - } -   -InlineintFindintVintf) { -     if(v==T) in         returnF; -     intres=0, T; to      for(inti=hd[v];i!=-1&&f>res;i=Nxt[i]) +         if(pos[to[i]]==pos[v]+1&&Fl[i]) -T=find (To[i],min (fl[i],f-res)), fl[i]-=t,fl[i^1]+=t,res+=T; the     if(!Res) *pos[v]=-1; $     returnRes;Panax Notoginseng } -   theInlineintDinic (void){ +     intres=0, T; A      while(BFS ()) the          while(t=find (S,inf)) +res+=T; -     returnRes; $ } $   -InlinevoidTopovoid){ -queue<int>Q; the      for(intI=1; i<=n*m;i++) -         if(!inch[i])WuyiQ.push (i), vis[i]=1; the      while(!Q.empty ()) { -         inttop=Q.front (); Q.pop (); Wu          for(intI=1; i<=n*m;i++) -             if(Mp[top][i]) { About                 inch[i]-=Mp[top][i]; $                 if(!inch[i]) -Q.push (i), vis[i]=1; -             } -     } A } +   theInlinevoidAddintSintXinty) { -fl[cnt]=s;to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++; $fl[cnt]=0; to[cnt]=x;nxt[cnt]=hd[y];hd[y]=cnt++; the } the   theSigned Main (void){ the     //freopen ("In.txt", "R", stdin); -     //freopen ("OUT.txt", "w", stdout); inMemsetinch,0,sizeof(inch)); thememset (hd,-1,sizeof(HD)); thescanf"%d%d", &n,&m); t=n*m+1; About      for(intI=1, s;i<=n*m;i++){ thescanf"%d%d",&val[i],&s); the          for(intj=1, x,y;j<=s;j++){ thescanf"%d%d", &x,&y), x++,y++; +             inch[(X-1) *m+y]++;mp[i][(x1) *m+y]++; -         } the         if(i%m)Bayi             inch[i]++,mp[i+1][i]++; the     } the topo (); -      for(intI=1; i<=n*m;i++) -         if(Vis[i]) { the             if(val[i]>0) theans+=Val[i],add (val[i],s,i); the             Else theAdd (-val[i],i,t); -              for(intj=1; j<=n*m;j++) the                 if(vis[j]&&Mp[i][j]) the Add (inf,j,i); the         }94printf"%d\n", Max (Ans-dinic (),0)); the     return 0;  the}//The cap ou pas Cap. Cap.
View Code

by Neighthorn

Bzoj 1565: [NOI2009] Plants vs. Zombies

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.