「网络流 24 题」方格取数
嘛,你把图分类一下 分成横坐标+纵坐标为奇偶... 然后在图上跑一个二分图最大权匹配 然后就是max(ans, 全部的-ans) 我代码写得有点... 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int inf=9999999; 5 int m,n,h[30005],tot=(-1),ans=0,sum=0; 6 int tu[305][305]; 7 struct node{ 8 int from,to,next,rest; 9 }e[300005]; 10 11 int zb(int x,int y){ 12 return (x-1)*n+y; 13 } 14 15 void add(int x,int y,int z){ 16 tot++; 17 e[tot].next=h[x]; 18 h[x]=tot; 19 e[tot].from=x; 20 e[tot].to=y; 21 e[tot].rest=z; 22 } 23 24 int dis[3005],g[3005],flow[3005]; 25 bool vis[3005]; 26 27 int bfs(int s,int t){ 28 queue<int>q; 29 dis[s]=0; 30 q.push(s);vis[s]=true; 31 while