The main topic: There are n individuals to participate in an activity, the activities required to participate in the people try not to have couples, organizers proposed four ways to reduce couples:
1. Two people with a height difference greater than 40
2. Same gender
3. Like different styles of music
4. Like the same sport
As long as one of them is satisfied, the two are not couples.
Now give the four data of n individuals, ask the maximum number of people who can be invited
Problem-solving ideas: This problem and POJ 1466 Girls and boys The question is very similar, but this problem gives the condition is not directly given, but we have to find the
As long as two people four conditions are not satisfied, you can think that they are couples (equivalent to POJ 1466 this problem of the secret love Relationship). So, find out 22 between the 4 conditions are not satisfied with the relationship, then this question and POJ 1466 this question very much like, then this question becomes to give a certain secret love relationship, ask you to find M personal, this m person of any two people is not a secret love relationship.
#include <cstdio>#include <cstring>#include <vector>#include <cstdio>using namespace STD;Const intN =510;Const intMAXN = the;structperson{intHeightCharSexCharSTYLE[MAXN], SPORT[MAXN]; }p[n];intn, Link[n],vis[n]; vector<int>G[n];voidInit () {scanf("%d", &n); for(inti =0; I < n; i++) {scanf("%d%c%s%s", &p[i].height, &p[i].sex, P[i].style, P[i].sport); G[i].clear (); } for(inti =0; I < n; i++) for(intj =0; J < N; J + +)if(I! = j) {if( ! ((P[i].height-p[j].height) > +|| P[j].height-p[i].height > +|| P[i].sex = = P[j].sex | |strcmp(p[i].style,p[j].style)! =0||strcmp(P[i].sport, p[j].sport) = =0)) G[i].push_back (j); }memset(Link,-1,sizeof(link));}BOOLDfsintu) { for(inti =0; I < g[u].size (); i++) {if(Vis[g[u][i]])Continue; Vis[g[u][i]] =1;if(Link[g[u][i]] = =-1|| DFS (Link[g[u][i]])) {Link[g[u][i]] = u;return true; } }return false;}voidHungary () {intAns =0; for(inti =0; I < n; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", N-ans/2);}intMain () {intTestscanf("%d", &test); while(test--) {init (); Hungary (); }return 0;}
POJ-2771 Guardian of Decency binary chart maximum matches