Pagini recente » Cod sursa (job #798577) | Cod sursa (job #1922801) | Cod sursa (job #183287) | Cod sursa (job #2931797) | Cod sursa (job #672165)
Cod sursa(job #672165)
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;
int n;
ifstream in("copii.in");
ofstream out("copii.out");
short int v[11][11];
int sol[11];
int nr;
bool validare(int m)
{
int b[11][11];
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
b[i][j]=0;
int s;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(v[i][j]==1)
b[sol[i]][sol[j]]=1;
for(int i=1;i<=m;i++)
for(int j=1;j<=m;j++)
if(i!=j)
if(b[i][j]!=0)
s++;
if(s>=m*m-m) return true;
else return false;
}
void test()
{
for(int i=1;i<=n;i++)out<<sol[i]<<" ";
out<<"\n";
}
void bkt(int p,int max)
{
if(p==n+1)
{
if(validare(max))
nr++;
//test();
return;
}
for(int i=1;i<=max+1;i++)
{
sol[p]=i;
if(i==max+1)
bkt(p+1,max+1);
else bkt(p+1,max);
}
}
int main()
{
string tmp;
in>>tmp;
n=atoi(tmp.c_str());
for(int i =1;i<n;i++)
{
in>>tmp;
for (int g=1;g<n;g++)
v[i][g]=atoi(tmp.substr(g,1).c_str());
}
bkt(1,0);
out<<nr-1;
// for(int i =0;i<n;i++)
// {
// for (int g=0;g<n;g++)
// cout<<v[i][g]<<" ";
// cout<<endl;
// }
return 0;
}