Cod sursa(job #1471975)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 15 august 2015 19:30:59
Problema Copii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <fstream>
#include <cstring>
 
using namespace std;
 
ifstream fin("copii.in");
ofstream fout("copii.out");
 
int n,sol ;
int a[13][13],aux[13][13],st[13],c[13];

bool verification()
{
    int sum = 0 ;
    for(int i = 1 ; i <= n ; i++)
	{
        sum = max(sum , st[i]);
    }
    
	if(sum == 1)
        return 0 ;
    
    for(int i = 1 ; i <= n ; i++)
	{
        for(int j = 1 ; j <= n ; j++)
		{
            aux[i][j] = 0 ;
            if(a[i][j] == 1 )
                aux[st[i]][st[j]] = 1;
        }
    }
    for(int i = 1 ; i <= sum ; i++)
	{
        for(int j = 1 ; j <= sum ; j++)
		{
            if(aux[i][j] == 0 && i != j)
                return 0;
        }
    }
    return 1;
}

  
void back(int top)
{
    if(top > n)  sol += verification();
    
	else
    
    for(int i = 1 ; i <= n ; i++){
        if(c[i - 1] != 0 || i == 1){
            st[top] = i ;
            ++c[i] ;
            back(top + 1);
            --c[i];
        }
    }
}  
  
  
int main()
{
    char ch ;
 
    fin >> n ;
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j <= n ; j++){
            fin >> ch ;
            a[i][j] = ch - '0';
        }
    }
 
    back(1);
    fout << sol ;
    return 0;
}