Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. string team[16]; int teamLen = 0;
  9. string tmpTeam[16]; int tmpTeamLen = 0;
  10.  
  11. bool nums[16] = {false};
  12. int n = 0, k = 0;
  13. bool rejectedPlayers[16];
  14.  
  15. bool isValid(string txt, string occ[][2]);
  16. void getTeam (string namesT[], string occ[][2], int start, int depth);
  17.  
  18. int main()
  19. {
  20.     scanf("%d %d", &n, &k);
  21.     string namesT[16];
  22.     string occ[16][2];
  23.  
  24.     for(int i = 0; i < n; i++)
  25.        cin >> namesT[i];
  26.  
  27.     for (int i = 0; i < k; i++)
  28.        cin >> occ[i][0] >> occ[i][1];
  29.  
  30.     if (k != 0)
  31.     {
  32.         getTeam (namesT, occ, 0, 1);
  33.         printf("%d \n", tmpTeamLen);
  34.         for (int i =0; i < tmpTeamLen; i++)
  35.        {
  36.            cout << tmpTeam[i] << "\n";
  37.        }
  38.    }
  39.    else
  40.    {
  41.        printf("%d \n", n);
  42.        for (int i =0; i < n; i++)
  43.        {
  44.            cout << namesT[i] << "\n";
  45.        }
  46.    }
  47.    return 0;
  48. }
  49.  
  50. void getTeam (string namesT[], string occ[][2], int start, int depth)
  51. {
  52.    if (depth == n)
  53.    {
  54.        if (teamLen >= tmpTeamLen)
  55.         {
  56.             std::copy(team, team + teamLen, tmpTeam);
  57.             tmpTeamLen = teamLen;
  58.         }
  59.         teamLen = 0;
  60.         return;
  61.     }
  62.  
  63.     for (int i = start; i < n; i++)
  64.    {
  65.        if (nums[i]) continue;
  66.        nums[i] = true;
  67.        if (isValid(namesT[i], occ))
  68.        {
  69.            string txt = namesT[i];
  70.            team[teamLen++] = txt;
  71.            getTeam(namesT, occ, i, depth+1);
  72.        }
  73.        nums[i] = false;
  74.    }
  75. }
  76.  
  77. bool isValid(string txt, string occ[][2])
  78. {
  79.    bool flag = true ;
  80.    string a = txt; int b = -1;
  81.  
  82.    for (int i = 0; i < k && flag; i++)
  83.    {
  84.        if (occ[i][0] == txt)
  85.        {
  86.            for (int j = 0; j < teamLen; j++)
  87.            {
  88.                if (team[i] == occ[i][1])
  89.                {
  90.                    b = 1;
  91.                    break;
  92.                }
  93.            }
  94.        }
  95.        else if (occ[i][1] == txt)
  96.        {
  97.            for (int j = 0; j < teamLen; j++)
  98.            {
  99.                if (team[i] == occ[i][0])
  100.                {
  101.                    b = 1;
  102.                    break;
  103.                }
  104.            }
  105.        }
  106.        if (b != -1) flag = false;
  107.    }
  108.  
  109.    return flag;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement