Cod sursa(job #728235)

Utilizator mattapoMatei Apolzan mattapo Data 28 martie 2012 16:28:08
Problema Copii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include<stdio.h>
char a[11][11];
bool echipai[11][11];
int n,v[11],nrechipe=0;
void prelucrare (int x)
{
	int i,j;
	for(i=1 ; i<=x ; i++)
		for(j=1 ; j<=x ; j++)
			echipai[i][j]=false;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			if (a[i][j]=='1')
				echipai[v[i]][v[j]]=true;
	for (i=1;i<=x;i++)
		for (j=1;j<=x;j++)
		{
			if (echipai[i][j]==false && i!=j)
				return;
			
		}
	nrechipe++;
	return;
}
void bkt (int p,int max)
{
	int i;
	if (p-1==n)
	{
		prelucrare(max-1);
		return;
	}
	for (i=1;i<=max;i++)
	{
		v[p]=i;
		if (i==max)
			bkt(p+1,max+1);
		else
			bkt(p+1,max);
	}
}
int main ()
{
	int i;
	freopen("copii.in","r",stdin);
	freopen("copii.out","w",stdout);
	scanf("%d\n",&n);
	for (i=1;i<=n;i++)
		gets(1+a[i]);
	bkt(1,1);
	printf("%d",nrechipe-1);
	return 0;
}