Cod sursa(job #423989)

Utilizator mihai995mihai995 mihai995 Data 24 martie 2010 15:17:21
Problema Copii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include <fstream>
using namespace std;
short int v[1<<4][1<<4],q[1<<4];
int n,k=1<<4,maxx;
long long cou;

ifstream in("copii.in");
ofstream out("copii.out");

void check()
{
	if (maxx==1)
		return;
	bool y[1<<4][1<<4];
	int i,j,nr=0;
	for (i=1;i<=maxx+1;i++)
		for (j=1;j<=maxx+1;j++)
			y[i][j]=false;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			if (v[i][j] && q[i]!=q[j])
				y[q[i]][q[j]]=true;
	for (i=1;i<=maxx;i++)
		for (j=1;j<=maxx;j++)
			nr+=y[i][j];
	/*for (i=1;i<=n;i++)
		out<<q[i]<<" ";
	out<<"\n\n";
	for (i=1;i<=maxx;i++)
	{
		for (j=1;j<=maxx;j++)
			out<<y[i][j]<<" ";
		out<<"\n";
	}
	out<<"\n";*/
	if (nr==maxx*(maxx-1))
		cou++;
}

void scrie()
{
	for(int i=1 ; i<=n ; ++i)
		out<<q[i]<<" ";
	out<<"\n";
}

void teams(int p)
{
	if (p==n+1)
	{
		check();
		return;
	}
	for (int i=1;i<=maxx;i++)
	{
		q[p]=i;
		teams(p+1);
	}
	q[p]=++maxx;
	teams(p+1);
	--maxx;
}	

int main()
{
	int i,j;
	char s[1<<4];
	in>>n;
	in.get();
	for (i=1;i<=n;i++)
	{
		in.getline(s,n+1);
		for (j=1;j<=n;j++)
		{
			v[i][j]=s[j-1]-'0';
			v[i][0]+=v[i][j];
		}
	}
	/*
	for (n=2;n<q;n++)
		teams(1);
	*/
	teams(1);
	out<<cou;
	return 0;
}