Link:
id=2289 ">http://poj.org/problem?id=2289
Serie A champions: there are n individuals, M-groups, and each person can be assigned to some groups. Asking how to divide can make the largest number of groups the fewest.
idea: This problem of two points + network flow can also do, I here is a binary map of the practice of multiple matching. Because a group is a one-to-many relationship, it is a multiple match. We have a two-part multi-match limit, and get the minimum limit to match the binary graph, the limit is the answer.
Templates for Online Search
#include <cstring> #include <string> #include <fstream> #include <sstream> #include < iostream> #include <iomanip> #include <cstdio> #include <cctype> #include <algorithm># include<queue> #include <map> #include <set> #include <vector> #include <stack> #include <ctime> #include <cstdlib> #include <functional> #include <cmath>using namespace std; #define PI ACOs ( -1.0) #define MAXN 500010#define eps 1e-6#define INF 0x7fffffff#define llinf 0x7fffffffffffffff#define seed 131# Define MOD 1000000007#define ll long long#define ull unsigned ll#define lson l,m,rt<<1#define rson m+1,r,rt<<1 |1const int M=2010;int bmap[m][m]; Subscript 0 starts with the bool Bmask[m];int nx,ny;int vcy[m];int cy[m][m];int limit; Multiple match limit bool Findpath (int u) {int i,j; for (i = 0; i < NY; i++) {if (Bmap[u][i] &&!bmask[i]) {bmask[i] = 1; if (Vcy[i] < limit) {cy[i][vcy[i]++] = u; ReTurn 1; } for (j = 0; J < Vcy[i]; J + +) {if (Findpath (Cy[i][j])) {cy[i][j] = u; return 1; }}}} return 0;} BOOL Mulmatch () {memset (vcy,0,sizeof (VCY)); for (int i=0; i < NX; i++) {memset (bmask,0,sizeof (bmask)); if (!findpath (i)) return 0; } return 1;} Char Str[5000];int main () {int i,j,x; while (scanf ("%d%d", &nx,&ny), nx| | NY) {memset (bmap,0,sizeof (BMAP)); for (i = 0; i < NX; i++) {scanf ("%s", str); Gets (str); StringStream sin (str); while (sin >> x) {bmap[i][x] = 1; }} int l = 0, r = NX; while (L < r) {limit = (L + r)/2; if (Mulmatch ()) r = limit; else L = limit + 1; } printf ("%d\n", R); } return 0;}
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
poj--2289--jamie& #39; s contact Groups "multiple matching + dichotomy answers" for "binary graphs"