在一个有 m*n 个方格的棋盘中,每个方格中有一个正整数。现要从方格中取数,使任意 2 个数所在方格没有公共边,且取出的数的总和最大。试设计一个满足要求的取数算法。对于给定的方格棋盘,按照取数要求编程找出总和最大的数。
这个题目也是很明显的网络流,奇偶性建图,最后总和-最小割即为答案
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
const int N=10100,M=202000,INF=(1<<29);
int tt=1,n,m,s,t,head[N],dis[N],vis[N],dep[N];
long long maxf=0;
struct pr {
int next,to,w;}a[M];
inline int read ()
{
int s=0;
char ch=getchar ();
while (ch>'9'||ch<'0') ch=getchar ();
while (ch>='0'&&ch<='9') {
s=s*10+ch-'0';ch=getchar ();}
return s;
}
void add (