Cod sursa(job #434394)

Utilizator juniorOvidiu Rosca junior Data 5 aprilie 2010 20:13:33
Problema Copii Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>

using namespace std;

int n, a[11], p[11][11], vmax, s, l, c;
char caracter;
ifstream fi("copii.in");
ofstream fo("copii.out");

void partitii (int l) { 
  int i, j, k, m, lsup; 
  bool ijok, PartitieOk;

  if (l <= n) { 
    lsup = vmax+1;
    for (i = 1; i <= lsup; i++) {
      a[l] = i; 
      if (i == lsup) 
        vmax++;
      partitii (l + 1); 
      if (i == lsup)
        vmax--; 
    }
  }
  else {
    PartitieOk = true;
    for (i = 1; i <= vmax and PartitieOk; i++)
      for (j = 1; j <= vmax and PartitieOk; j++)
        if (i != j) {
          ijok = false;
          for (k = i; k <= n and not ijok; k++)
            for (m = j; m <= n and not ijok; m++)
              if (k != m) if (a[k] == i) if (a[m] == j) 
                ijok = p[k][m];
          PartitieOk &= ijok;
        }
    if (PartitieOk)
      s++;
  }
}

int main () {
  fi >> n;
  for (l = 1; l <= n; l++)
    for (c = 1; c <= n; c++) {
      fi >> caracter;
      p[l][c] = (caracter == '0' ? 0 : 1);
    }
  partitii (1);
  fo << s-1; // Scadem 1 pentru a elimina partitia care are o singura multime care contine toate elementele.
}