Pagini recente » Cod sursa (job #619296) | Cod sursa (job #108820) | Cod sursa (job #2347013) | Cod sursa (job #777491) | Cod sursa (job #2636953)
#include <bits/stdc++.h>
#define DIM 15
using namespace std;
int a[DIM][DIM],f[DIM],f2[DIM],v[DIM][DIM];
vector <pair<int,int> > mch;
pair <int,int> x[DIM];
char s[DIM];
int n,i,j,sol;
void back (int pas){
if (pas == n+1){
int k = x[n].second;
if (k == 1)
return;
for (int i=1;i<=k;i++)
for (int j=1;j<=k;j++)
v[i][j] = 0;
int cnt = 0;
for (auto it : mch){
int a = it.first, b = it.second;
if (!v[x[a].first][x[b].first] && x[a].first != x[b].first)
cnt++;
v[x[a].first][x[b].first] = 1;
}
if (cnt == (k-1)*k)
sol++;
return;
}
for (int i=1;i<=n;i++){
x[pas].first = i;
if (x[pas].first <= x[pas-1].second+1){
x[pas].second = max (x[pas-1].second,i);
back(pas+1);
x[pas].second = x[pas-1].second;
}}}
int main (){
ifstream fin ("copii.in");
ofstream fout ("copii.out");
fin>>n;
for (i=1;i<=n;i++){
fin>>s+1;
for (j=1;j<=n;j++){
a[i][j] = s[j] - '0';
if (a[i][j])
mch.push_back(make_pair(i,j));
}
}
back(1);
fout<<sol;
return 0;
}