Cod sursa(job #2482063)

Utilizator stan_flaviusStan Flavius Stefan stan_flavius Data 27 octombrie 2019 19:16:20
Problema Copii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.67 kb
#include <fstream>
#include <cstring>
#include <vector>
#define nmax 11

using namespace std;
ifstream fin("copii.in");
ofstream fout("copii.out");

int x[11],mx[11];
int cnt=0;
int ct;
int graf_copii[nmax][nmax];
int graf_echipe[nmax][nmax];

bool verif(int k)
{
    vector< vector<int> >echipe;
    for(int i=1; i<=mx[ct]; i++)
      {
          vector<int>echipa;
          for(int j=1; j<=ct; j++)
                if(x[j]==i)
                    {
                        //fout<<j;
                        echipa.push_back(j-1);
                    }
          //fout<<"*";
          echipe.push_back(echipa);
      }

    int n=echipe.size();
    if(n==1) return 0;

    for(int i=0; i<n-1; i++) ///sel echipa 1
        {
            int ct_echipa_1=echipe[i].size();
            for(int j=i+1; j<n; j++) ///sel echipa 2
                {
                    int ct_echipa_2=echipe[j].size();
                    for(int k=0; k<ct_echipa_1; k++)
                        {
                            for(int l=0; l<ct_echipa_2; l++)
                                {
                                    //fout<<echipe[i][k]<<" "<<echipe[j][l]<<" "<<graf_copii[echipe[i][k]][echipe[j][l]]<<"\n";
                                    if(graf_copii[echipe[i][k]][echipe[j][l]]==1)
                                        {
                                            graf_echipe[i][j]=1;
                                            graf_echipe[j][i]=1;
                                        }
                                }
                        }
                }
        }
    /*fout<<"\n";
    for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
                fout<<graf_echipe[i][j]<<" ";
            fout<<"\n";
        }
    fout<<"\n";
*/
    for(int i=0; i<n; i++)
        {
            int ct=0;
            for(int j=0; j<n; j++)
                {
                    if(graf_echipe[i][j]==1) ct++;
                }
            if(ct!=n-1) return 0;
        }
    return 1;
}

void Back(int k)
{
    for(int i=1; i<=mx[k-1]+1; i++)
        {
            x[k]=i;
            if(i<mx[k-1]) mx[k]=mx[k-1];
            else mx[k]=i;
            if(k==ct)
                {
                    if(verif(k)) cnt++;
                }
            else Back(k+1);
        }
}


int main()
{
    fin>>ct;
    for(int i=0; i<ct; i++)
        {
            char s[nmax];
            fin>>s;
            for(int j=0; j<strlen(s); j++)
                {
                    graf_copii[i][j]=s[j]-'0';
                }
        }

    x[1]=1; mx[1]=1;
    Back(2);

    fout<<cnt;
    return 0;
}