落谷P4728(最大二分匹配)

题解思路:我们把数组这些元素看成点然后两个点之间一条有向边的前提为i

#include
using namespace std;
const int mx = 2e3+5;
const int inf = 0x3f3f3f3f;
int dx[mx];
int dy[mx];
int x[mx];
int y[mx];
bool vis[mx];
int a[mx];
int dis;
int n;
bool search(){
	dis = inf;
	memset(dx,0,sizeof(dx));
	memset(dy,0,sizeof(dy));
	queueq;
	for(int i = 1; i <= n; i++)
		if(!x[i]){
			dx[i] = 1;
			q.push(i);
		}
	while(!q.empty()){
		int u = q.front();
		q.pop();
		if(dx[u]>=dis)
			continue;
		for(int i = u+1; i <= n; i++){
			if(a[i]>a[u]&&dy[i]==0){
				dy[i] = dx[u]+1;
				if(y[i]) {dx[y[i]]=dy[i]+1,q.push(y[i]);}
				else dis = dy[i];
			}
		} 
	}
	return dis!=inf;
}
bool find(int u){
	for(int i = u+1; i <= n; i++)
		if(a[u]=n-2)
			puts("Yes!");
		else
			puts("No!");
	} 
    return 0;
} 

 

你可能感兴趣的:(二分匹配)