正解:网络流

解题报告:

传送门$QwQ$

看到不能出现给定的讨厌的图形,简单来说就,特殊边两侧的方格不能同时再连方格.

所以如果出现,就相当于是四种方案?就分别炸四个格子.

然后冷静分析一波之后发现对于特殊边两侧的格子炸那个是没有影响的?于是这两个格子就只用选较小的一个炸就好,于是现在就变成了三种方案,可以考虑和之前做的那道,酒店之王,差不多的建图,$over$

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define ll long long
#define mp make_pair
#define P pair<int,int>
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define n(i) edge[i].nxt
#define ri register int
#define rb register int
#define rc register char
#define rp(i,x,y) for(int i=x;i<=y;++i)
#define my(i,x,y) for(int i=x;i>=y;--i)
#define e(i,x) for(int i=head[x];~i;i=n(i)) const int N=5e5+,inf=1e9;
int n,dep[N],head[N],cur[N],S,T,ed_cnt=-,col[N],mvx[]={,-,,},mvy[]={,,,-};
struct ed{int to,nxt,wei;}edge[N<<];
struct node{int x,y,val;}nod[N];
map<P,int>mapp; il int read()
{
rc ch=gc;ri x=;rb y=;
while(ch!='-' && (ch>'' || ch<''))ch=gc;
if(ch=='-')ch=gc,y=;
while(ch>='' && ch<='')x=(x<<)+(x<<)+(ch^''),ch=gc;
return y?x:-x;
}
il void ad(ri x,ri y,ri z)
{
//printf("%d -> %d : %d\n",y,x,z);
edge[++ed_cnt]=(ed){x,head[y],z};head[y]=ed_cnt;edge[++ed_cnt]=(ed){y,head[x],};head[x]=ed_cnt;}
il bool bfs()
{
queue<int>Q;Q.push(S);memset(dep,,sizeof(dep));dep[S]=;
while(!Q.empty())
{
ri nw=Q.front();Q.pop();//printf("nw=%d\n",nw);
e(i,nw)if(w(i) && !dep[t(i)]){dep[t(i)]=dep[nw]+,Q.push(t(i));if(t(i)==T)return ;}
}
return ;
}
il int dfs(ri nw,ri flow)
{
if(nw==T || !flow)return flow;ri ret=;
for(ri &i=cur[nw];~i;i=n(i))
if(w(i) && dep[t(i)]==dep[nw]+)
{ri tmp=dfs(t(i),min(flow,w(i)));ret+=tmp,w(i)-=tmp;w(i^)+=tmp,flow-=tmp;}
return ret;
}
il int dinic(){int ret=;while(bfs()){rp(i,S,T)cur[i]=head[i];while(int d=dfs(S,inf))ret+=d;}return ret;}
il int cal(ri x,ri y){return (*(x%>=)+(^((x+y)&)));}
il void build1(ri nw)
{
rp(i,,)
{
ri tx=nod[nw].x+mvx[i],ty=nod[nw].y+mvy[i],to=mapp[mp(tx,ty)];
if(to){if(col[to]==)ad(to,nw,min(nod[nw].val,nod[to].val));else ad(nw,to,inf);}
}
}
il void build2(ri nw)
{
rp(i,,)
{
ri tx=nod[nw].x+mvx[i],ty=nod[nw].y+mvy[i],to=mapp[mp(tx,ty)];
if(to){if(col[to]!=)ad(to,nw,inf);}
}
} int main()
{
//freopen("3756.in","r",stdin);freopen("3756.out","w",stdout);
read();read();n=read();S=;T=n+;memset(head,-,sizeof(head));
rp(i,,n){nod[i]=(node){read(),read(),read()};mapp[mp(nod[i].x,nod[i].y)]=i;col[i]=cal(nod[i].x,nod[i].y);}
rp(i,,n)
{
//printf("col[%d]=%d\n",i,col[i]);
switch(col[i])
{
case :{ad(i,S,nod[i].val);break;}
case :{build1(i);break;}
case :{build2(i);break;}
case :{ad(T,i,nod[i].val);break;}
}
}
printf("%d\n",dinic());
return ;
}
05-20 02:38