http://poj.org/problem?id=3487
Gale-Shapley算法求稳定婚姻
# include<iostream>
# include<map>
# include<vector>
using namespace std;
# define N 30
int n;
char m[N],w[N];
vector<vector<char> > mL,wL,MproposeW;
map<char, char> MmatchW;
map<char, char> WmatchM;
void FindFreeMan(int &a, int &b)
{
for(int j=0;j<n;j++) //for each man
{
if(MmatchW.count(m[j])==0) //a free man
{
for(int k=0;k<MproposeW[j].size();k++)
{
if(MproposeW[j][k]!='#') //also hasn't propose to all woman(woman k)
{
a=j;
b=k;
return;
}
}
}
}
a=-1;
b=-1;
}
//判断(in the j-th man's list)the k-th woman是否喜欢the j-th man超过当前的约会男友WmatchM[mL[j][k]](mi)
bool LoveMore(int k, int j)
{
char mj=m[j];
char mi=WmatchM[mL[j][k]];
int t;
for(t=0;t<n;t