// ** Start of PerfectMatch ******************************* // Name: PerfectMatch by Kuhn_Munkras O(n^3) // Description: w is the adjacency matrix, nx,ny are the size of x and y, // lx, ly are the lables of x and y, fx[i], fy[i] is used for marking // whether the i-th node is visited, matx[x] means x match matx[x], // maty[y] means y match maty[y], actually, matx[x] is useless, // all the arrays are start at 1
#i nclude <iostream>
using namespace std;
const int MAXN = 110; const int INF = 0x7FFFFFFF;
int nx, ny, w[MAXN][MAXN], lx[MAXN], ly[MAXN]; int fx[MAXN], fy[MAXN], matx[MAXN], maty[MAXN];
int path(int u) { fx[u] = 1; for (int v = 1; v <= ny; v++) if (lx[u] + ly[v] == w[u][v] && fy[v] < 0) { fy[v] = 1; if (maty[v] < 0 || path(maty[v])) { matx[u] = v; maty[v] = u; return 1; } } return 0; }
string del_blank(string s) { string ret=""; int i,len=s.size(); for (i=0;i<len;i++) if (s[i]!=' ') ret.push_back(s[i]); return ret; }
string del(string s) { int i,cnt=0,len=s.size(); if (s[0]=='(' && s[len-1]==')') { string t=s; int flag=1; t[0]='.'; t[len-1]='.'; for (i=0;i<len;i++) { if (t[i]=='(') cnt++; if (t[i]==')') cnt--; if (cnt<0) { flag=0; break; } } if (flag) { t=""; for (i=1;i<len-1;i++) t.push_back(s[i]); return del(t); } else re ……