Cod sursa(job #996961)

Utilizator narcis_vsGemene Narcis - Gabriel narcis_vs Data 12 septembrie 2013 22:52:51
Problema Copii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <fstream>
#include <cstring>
#include <cstdlib>

#define Nmax 20
using namespace std;

int n,sol,cnt,g[Nmax];
char Graph[Nmax][Nmax];
bool team[Nmax][Nmax];

inline void Read()
{
    ifstream f("copii.in");
    f>>n;
    for(int i = 1;i <= n;++i)
        f>>(Graph[i]+1);
    f.close();
}
inline bool Solve()
{
    if(cnt==1)
        return 0;
    int i,j;
    memset(team,0,sizeof(team));
    for(i=1;i<=n;++i)
        for(j = 1;j <= n; ++j)
            if(Graph[i][j]-'0')
                team[g[i]][g[j]] = 1;
    for(i = 1;i <= cnt;++i)
        for(j = 1;j <= cnt;++j)
            if(i!=j && !team[i][j])
                return 0;
    return 1;
}

inline void Back(const int k)
{
    if(k==n+1)
    {
        sol += Solve();
        return ;
    }
    for(int i = 1;i <= cnt; ++i)
    {
        g[k] = i;
        Back(k+1);
    }
    g[k] = ++cnt;
    Back(k+1);
    --cnt;
}

inline void Write()
{
    ofstream g("copii.out");
    g<<sol<<"\n";
    g.close();
}

int main()
{
    Read();
    Back(1);
    Write();
    return 0;
}