标签:highlight define ack [1] space col def vector san
开个坑不然刷题没动力QAQ
干脆叫做刷题计划。。。
既然开了坑就要填满QWQ,加油!
正好实力弱多刷题也挺好的QAQ
1/50
Bzoj-1001 狼抓兔子
题意:求最小割
分析:因为最小割=最大流,直接跑一遍dinic求最大流就好了。最大流参照的是黄学长的模板
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
#define maxn 1000005
#define ll long long
int read(){
int x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
int n,m;
int h[maxn],q[maxn];
struct pos{
int to,from,v,nxt;
}e[maxn*6];
int head[maxn],edge;
void add(int x,int y,int z){
e[++edge].to=y;e[edge].from=x;e[edge].v=z;
e[edge].nxt=head[x];head[x]=edge;
}
bool bfs(){
int now;memset(h,-1,sizeof(h));
int hd=0,tl=1;
q[hd]=1;h[1]=0;
while(hd!=tl){
now=q[hd++];
for(int i=head[now];i;i=e[i].nxt){
if(e[i].v&&h[e[i].to]==-1){
h[e[i].to]=h[now]+1;
q[tl++]=e[i].to;
}
}
}
return h[n*m]!=-1;
}
int dfs(int x,int mn){
if(x==n*m) return mn;
int w,used=0;
for(int i=head[x];i;i=e[i].nxt)
if(e[i].v&&h[e[i].to]==h[x]+1){
w=mn-used;w=dfs(e[i].to,min(w,e[i].v));
e[i].v-=w;
e[i+1].v+=w;
used+=w;
if(used==mn) return mn;
}
if(!used) h[x]=-1;
return used;
}
int ans;
int dinic(){while(bfs())ans+=dfs(1,0x7fffffff);}
int main(){
n=read();m=read();
for(int i=1;i<=n;i++)
for(int j=1;j<m;j++){
int x=read();
add((i-1)*m+j,(i-1)*m+j+1,x);
add((i-1)*m+j+1,(i-1)*m+j,x);
}
for(int i=1;i<n;i++)
for(int j=1;j<=m;j++){
int x=read();
add((i-1)*m+j,i*m+j,x);
add(i*m+j,(i-1)*m+j,x);
}
for(int i=1;i<n;i++)
for(int j=1;j<m;j++){
int x=read();
add((i-1)*m+j,i*m+j+1,x);
add(i*m+j+1,(i-1)*m+j,x);
}
dinic();printf("%d\n",ans);
}
未完待续
标签:highlight define ack [1] space col def vector san
原文地址:http://www.cnblogs.com/ZincSabian/p/7470552.html