GastonFontenla

Timus: 1208 - Legendary Teams Contest

Jun 5th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #define ll long long
  5.  
  6. bool GB(ll m, ll x)
  7. {
  8.     return ((m) & (1LL << (x)));
  9. }
  10.  
  11. void SB(ll &m, ll x)
  12. {
  13.     m = ((m) | (1LL <<(x)));
  14. }
  15.  
  16. using namespace std;
  17.  
  18. struct Equipo
  19. {
  20.     ll a, b, c;
  21. };
  22.  
  23. struct Grafo
  24. {
  25.     vector <Equipo> v;
  26.     map<string, int> mapa;
  27.  
  28.     int id(string a)
  29.     {
  30.         if(mapa[a] == 0)
  31.             mapa[a] = mapa.size();
  32.         return mapa[a];
  33.     }
  34.  
  35.     int maxCant;
  36.  
  37.     void solve(int i, int c, ll s)
  38.     {
  39.         maxCant = max(maxCant, c);
  40.         if(i >= v.size())
  41.             return;
  42.  
  43.         ///Ver si el equipo i puede participar
  44.         solve(i+1, c, s);
  45.         if(!GB(s, v[i].a) && !GB(s, v[i].b) && !GB(s, v[i].c)) ///Si puede participar
  46.         {
  47.             SB(s, v[i].a);
  48.             SB(s, v[i].b);
  49.             SB(s, v[i].c);
  50.             solve(i+1, c+1, s);
  51.         }
  52.     }
  53.  
  54.     void leer()
  55.     {
  56.         int n;
  57.         cin >> n;
  58.         v = vector <Equipo> (n);
  59.  
  60.         string sa, sb, sc;
  61.  
  62.         for(int i=0; i<n; i++)
  63.         {
  64.             cin >> sa >> sb >> sc;
  65.             v[i].a = id(sa)-1;
  66.             v[i].b = id(sb)-1;
  67.             v[i].c = id(sc)-1;
  68.         }
  69.  
  70.         ///Probar todas las combinaciones!! :D
  71.         maxCant = 0;
  72.         ll z = 0;
  73.         solve(0, 0, z);
  74.  
  75.         cout << maxCant << endl;
  76.     }
  77. };
  78.  
  79. int main()
  80. {
  81.     Grafo g;
  82.     g.leer();
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment