
1565: [NOI2009]植物大战僵尸
发布日期:2021-05-06 23:49:03
浏览次数:18
分类:精选文章
本文共 2400 字,大约阅读时间需要 8 分钟。
题意
题解
很裸的一个最大权闭合子图啊。。
如果依赖关系有环,活着说他的依赖关系和环有关,就把这个点废掉。。 然后你就构图跑最大权闭合子图就好了#include#include #include #include #include using namespace std;const int N=23*33;const int MAX=1<<30;struct qt{ int ooo;//得分 int w; int X[N],Y[N];//攻击范围}s[N];struct qy{ int x,y,last,z;}ss[N*N];//指向的是他需要谁int num,Last[N];int n,m;int P (int x,int y){ return (x-1)*m+y;}void Init (int x,int y){ num++; ss[num].x=x;ss[num].y=y; ss[num].last=Last[x]; Last[x]=num;}int dfn[N],low[N],belong[N],cnt,sta[N],lalal,shen;bool in[N];int TT[N];int mymin (int x,int y){ return x y?x:y;}void dfs1 (int x){ dfn[x]=low[x]=++lalal; sta[++cnt]=x; in[x]=true; for (int u=Last[x];u!=-1;u=ss[u].last) { int y=ss[u].y; if (dfn[y]==-1) { dfs1(y); low[x]=mymin(low[x],low[y]); } else if (in[y]) low[x]=mymin(dfn[y],low[x]); } if (low[x]==dfn[x]) { shen++;TT[shen]=0; int now; do { now=sta[cnt--]; belong[now]=shen; in[now]=false; TT[shen]++; }while (now!=x); }}qy e[N*N*2];int last[N];int st,ed;void init (int x,int y,int z){ num++; e[num].x=x;e[num].y=y;e[num].z=z; e[num].last=last[x]; last[x]=num; swap(x,y);z=0; num++; e[num].x=x;e[num].y=y;e[num].z=z; e[num].last=last[x]; last[x]=num;}int h[N];bool Bt (){ memset(h,-1,sizeof(h));h[st]=1; queue q; q.push(st); while (!q.empty()) { int x=q.front();q.pop(); for (int u=last[x];u!=-1;u=e[u].last) { int y=e[u].y; if (e[u].z>0&&h[y]==-1) { h[y]=h[x]+1; q.push(y); } } } return h[ed]!=-1;}int dfs (int x,int f){ if (x==ed) return f; int s1=0; for (int u=last[x];u!=-1;u=e[u].last) { int y=e[u].y; if (e[u].z>0&&h[y]==h[x]+1&&s1 1) ok[u]=0; for (int u=1;u<=n*m;u++) if (ok[u]==-1) dfs(u); num=1;memset(last,-1,sizeof(last)); st=n*m+1;ed=st+1; int ans=0; for (int u=1;u<=n*m;u++) if (ok[u]==1) { if (s[u].ooo>0) init(st,u,s[u].ooo),ans=ans+s[u].ooo; else init(u,ed,-s[u].ooo); for (int i=Last[u];i!=-1;i=ss[i].last) { int y=ss[i].y; init(u,y,MAX); } } while (Bt()) ans=ans-dfs(st,MAX); printf("%d\n",ans);}void Ins (){ num=0;memset(Last,-1,sizeof(Last)); scanf("%d%d",&n,&m); for (int u=1;u<=n;u++) for (int i=1;i<=m;i++) { int x=P(u,i); scanf("%d",&s[x].ooo); scanf("%d",&s[x].w); for (int j=1;j<=s[x].w;j++) { int xx,yy; scanf("%d%d",&xx,&yy); xx++;yy++; Init(P(xx,yy),x); } if (i!=m) Init(P(u,i),P(u,i+1)); } /*for (int u=1;u<=num;u++) printf("%d %d\n",ss[u].x,ss[u].y);*/}int main(){ Ins(); solve(); return 0;}
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2025年04月02日 13时30分06秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Docker 服务
2019-03-06
第一眼就心动的人还怎么做朋友
2019-03-06
Cassandra数据建模
2019-03-06
Elasticsearch Web管理工具
2019-03-06
Git 配置SSH公钥、私钥
2019-03-06
极客时间离线课堂
2019-03-06
Spring Session
2019-03-06
koa2 中间件里面的next到底是什么
2019-03-06
在create-react-app创建的项目下允许函数绑定运算符
2019-03-06
博客园新闻频道开始公开测试
2019-03-06
评论表聚集索引引起的评论超时问题
2019-03-06
博客园上海俱乐部4月份活动通知邀请函已经发出!
2019-03-06
上周热点回顾(5.24-5.30)
2019-03-06
Internet Explorer 10 专题上线
2019-03-06
云计算之路-阿里云上:0:25~0:40网络存储故障造成网站不能正常访问
2019-03-06
网站故障公告1:使用阿里云RDS之后一个让人欲哭无泪的下午
2019-03-06
上周热点回顾(12.31-1.6)
2019-03-06
上周热点回顾(1.21-1.27)
2019-03-06
上周热点回顾(6.3-6.9)
2019-03-06
上周热点回顾(8.12-8.18)
2019-03-06