Cod sursa(job #434407)

Utilizator juniorOvidiu Rosca junior Data 5 aprilie 2010 20:48:08
Problema Copii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>

using namespace std;

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

void partitii (int l) { 
  int i, j, lsup, s; 
  int pm[11][11];

  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 {
    memset (pm, 0, sizeof(pm));
    for (i = 1; i <= n; i++)
      for (j = 1; j <= n; j++)
        if (i != j and a[i] != a[j] and p[i][j]) {
          pm[a[i]][a[j]] = 1;
        }
    s = 0;
    for (i = 1; i <= vmax; i++)
      for (j = 1; j <= vmax; j++)
        s += pm[i][j];
    if (s == vmax*vmax-vmax)
      sol++;
  }
}

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 << sol-1; // Scadem 1 pentru a elimina partitia care are o singura multime care contine toate elementele.
}