https://www.luogu.org/problem/P3356
题意: q ∗ p q*p q∗p的网格,有障碍/平坦地面/岩石标本,求从左上角到右下角最多运送车辆的情况下,运送的石子数最多,输出车辆走的路径。
思路:35*35的图很小,拆点建图,有石子的一条边容量为1,费用-1,另一条容量INF,费用0.
最后的输出答案跑n遍dfs,每次沿着flow>0的边走到终点,并把路径上所有的边flow-1.
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000*2+100;
const int INF=0x3f3f3f3f;
typedef long long ll;
struct Edge{
int from,to,cap,flow,cost;
};
struct MCMF{
int c,r;
int n,m,s,t;
vector<Edge> edges;
vector<int> G[maxn];
int inq[maxn];
ll d[maxn];
int p[maxn];
int a[maxn];
void init()
{
int x;
cin>>n>>c>>r;
s=c*r*2,t=s+1;
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
scanf("%d",&x);
int from=(i*c+j)*2,to=from+