Pagini recente » Cod sursa (job #2895273) | Cod sursa (job #2498280) | Cod sursa (job #3271192) | Cod sursa (job #1951955) | Cod sursa (job #2475901)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream fin("copii.in"); ofstream fout("copii.out");
int n , ans=0;
vector <string> g(10);
bool check(int max , vector<int> &cmb)
{
vector<vector<bool>> ok(max + 2, vector<bool> (max + 2, false));
int anss=0;
for(int i=0 ; i<n ; i++)
for(int j=0 ; j<n ; j++)
{
if(cmb[i]!=cmb[j] && g[i][j] == '1' && !ok[cmb[i]][cmb[j]])
{
ok[cmb[i]][cmb[j]] = true;
anss++;
}
}
return anss == max * (max-1);
}
void bkt(int nr , int maxx , vector<int> &cmb)
{
if(nr == n)
{
if(check(maxx, cmb))
ans++;
return;
}
for(int i=1 ; i<= maxx + 1 ; i++)
{
cmb[nr] = i;
bkt(nr + 1, max(maxx, i), cmb);
}
}
int main()
{
fin >> n;
for(int i=0 ; i<n ; i++)
fin >> g[i];
vector<int> cmb(n);
bkt(0 , 0 , cmb);
fout << ans-1;
return 0;
}