Cod sursa(job #2475907)

Utilizator stefzahZaharia Stefan Tudor stefzah Data 17 octombrie 2019 19:18:10
Problema Copii Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("copii.in");
ofstream fout("copii.out");
int N,v[15],ct;
string s;
int a[15][15],b[15][15];
bool Verificare(int mx)
{int i,j;
 bool ok=1;
 for(i=1;i<=N;i++)
    for(j=1;j<=N;j++)
       b[i][j]=0;

 for(i=1;i<=N;i++)
    for(j=1;j<=N;j++)
       if(a[i][j]==1)b[v[i]][v[j]]=1;

 for(i=1;i<=mx;i++)
    for(j=1;j<=mx;j++)
        if(i!=j&&b[i][j]==0){ok=0;i=mx+1;break;}

    if(mx>1)return ok;
    else return false;
}
void Back(int top,int mx)
{int i;
 if(top==N+1&&Verificare(mx)==1)ct++;
    else if(top<=N)
    {for(i=1;i<=mx+1;i++)
        {v[top]=i;
         Back(top+1,max(mx,i));
        }
    }
}
int main()
{int i,j;
 fin>>N;
 for(i=1;i<=N;i++)
    {fin>>s;
     for(j=0;j<N;j++)
     {if(s[j]=='1')a[i][j+1]=1;
       else a[i][j+1]=0;
       //cout<<a[i][j+1]<<" ";
     }
    }
 Back(1,0);
 fout<<ct;
}