Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- #include <stdio.h>
- using namespace std;
- string team[16]; int teamLen = 0;
- string tmpTeam[16]; int tmpTeamLen = 0;
- bool nums[16] = {false};
- int n = 0, k = 0;
- bool rejectedPlayers[16];
- bool isValid(string txt, string occ[][2]);
- void getTeam (string namesT[], string occ[][2], int start, int depth);
- int main()
- {
- scanf("%d %d", &n, &k);
- string namesT[16];
- string occ[16][2];
- for(int i = 0; i < n; i++)
- cin >> namesT[i];
- for (int i = 0; i < k; i++)
- cin >> occ[i][0] >> occ[i][1];
- if (k != 0)
- {
- getTeam (namesT, occ, 0, 1);
- printf("%d \n", tmpTeamLen);
- for (int i =0; i < tmpTeamLen; i++)
- {
- cout << tmpTeam[i] << "\n";
- }
- }
- else
- {
- printf("%d \n", n);
- for (int i =0; i < n; i++)
- {
- cout << namesT[i] << "\n";
- }
- }
- return 0;
- }
- void getTeam (string namesT[], string occ[][2], int start, int depth)
- {
- if (depth == n)
- {
- if (teamLen >= tmpTeamLen)
- {
- std::copy(team, team + teamLen, tmpTeam);
- tmpTeamLen = teamLen;
- }
- teamLen = 0;
- return;
- }
- for (int i = start; i < n; i++)
- {
- if (nums[i]) continue;
- nums[i] = true;
- if (isValid(namesT[i], occ))
- {
- string txt = namesT[i];
- team[teamLen++] = txt;
- getTeam(namesT, occ, i, depth+1);
- }
- nums[i] = false;
- }
- }
- bool isValid(string txt, string occ[][2])
- {
- bool flag = true ;
- string a = txt; int b = -1;
- for (int i = 0; i < k && flag; i++)
- {
- if (occ[i][0] == txt)
- {
- for (int j = 0; j < teamLen; j++)
- {
- if (team[i] == occ[i][1])
- {
- b = 1;
- break;
- }
- }
- }
- else if (occ[i][1] == txt)
- {
- for (int j = 0; j < teamLen; j++)
- {
- if (team[i] == occ[i][0])
- {
- b = 1;
- break;
- }
- }
- }
- if (b != -1) flag = false;
- }
- return flag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement