1. Fazan
#include<iostream>
using namespace std;
int n,p,x[10],nr=0,c=0,v[100],Sm[100],mx=0;
char a[100][100];
int afisare(int n)
{for(int i=0;i<=n;i++)
cout<<a[x[i]]<<" ";
nr++;
cout<<endl;}
int verif(int i)
{if(i>1 && strcmp(a[x[i]],a[x[i-1]])==0)
return 0;
if(i==1 && (a[x[i]][0]!=a[x[i-1]][strlen(a[x[i-1]])-2] || a[x[i]][1]!=a[x[i-1]][strlen(a[x[i-1]])-1]))
return 0;
for(int j=1;j<i;j++)
if(x[i]==x[j])
return 0;
if(i>1 && (a[x[i]][0]!=a[x[i-1]][strlen(a[x[i-1]])-2] || a[x[i]][1]!=a[x[i-1]][strlen(a[x[i-1]])-1]))
return 0;
return 1;
}
void back(int i)
{int j;
for(j=1;j<=n;j++)
{
x[i]=j;
if(verif(i))
{afisare(i);
if(i>mx)
{mx=i;
for(int k=1;k<=i;k++)
Sm[k]=x[k];
}
if(i<=n)
back(i+1);
}
}
}
int main()
{int i,j,nn,k=0;
cin>>n;
for(i=0;i<=n;i++)
cin>>a[i];
back(1);
cout<<endl<<endl<<"Cea mai lunga"<<endl;
for(i=0;i<=mx;i++)
cout<<a[Sm[i]]<<" ";
cout<<"este formatata din "<<mx<<" cuvinte";
cout<<endl<<nr<<" solutii";
}