Pagini recente » Diferente pentru utilizator/darius_c intre reviziile 11 si 12 | Cod sursa (job #2679267) | Cod sursa (job #421601)
Cod sursa(job #421601)
#include <stdio.h>
#include <vector>
using namespace std;
#define maxN 15
int N;
char A[maxN][maxN];
int v[maxN], a[maxN], Sol;
vector <int> x[maxN];
void verif () {
int i, j, ok;
vector <int> :: iterator k, l;
for (i = 1; i <= N; ++ i)
x[i].clear();
for (i = 1; i <= N; ++ i)
x[v[i]].push_back(i);
for (i = 1; x[i].size() && i <= N; ++ i)
for (j = 1; x[j].size() && i <= N; ++ j)
if (i != j) {
ok = false;
for (k = x[i].begin(); k != x[i].end() && !ok; ++ k)
for (l = x[j].begin(); l != x[j].end() && !ok; ++ l)
if (A[*k][*l])
ok = true;
if (!ok)
return;
}
++ Sol;
}
void back (int k, int n) {
if (k == n + 1) {
verif();
return ;
}
for (int i = 1; i <= n; ++ i)
if (a[i - 1]) {
a[i] ++;
v[k] = i;
back(k + 1, n);
a[i] --;
}
}
int main () {
int i;
freopen("copii.in", "r", stdin);
freopen("copii.out", "w", stdout);
scanf("%d", &N);
for (i = 1; i <= N; ++ i)
gets(A[i] + 1);
a[0] = 1;
back(1, N);
printf("%d\n", Sol);
}