Pagini recente » Cod sursa (job #1449084) | Cod sursa (job #601546) | Cod sursa (job #1443746) | Cod sursa (job #1172268) | Cod sursa (job #2236945)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("copii.in");
ofstream fout("copii.out");
int n,V[11][3],P[11];
long long pos=0;
void bk(int k){//k-adancimea (nr de cifre folosite sau copii inclusi)
if(k>n){
/*for(int i=1;i<=n && V[i][1]!=0;i++){
cout<<" ( ";
bool s=true;
for(int j=1;j<=n;j++){
if(V[i][1]&(1<<j)){
if(!s)cout<<" , ";
else s=false;
cout<<j;
}
}
cout<<" ) ";
}
cout<<'\n'; */
int i;
for(i=1;i<=n && V[i][1]!=0;i++){
for(int j=1;j<=n && i!=j && V[j][1]!=0;j++){
if(!(V[i][2]&V[j][1])){
// printf("!(V[%d][2]&V[%d][1])=!(%d&%d)=%d",i,j,V[i][2],V[j][1],!(V[i][2]&V[j][1]));
// cout<<"X\n";
return;
}
}
}
if(i>2){
pos++;
}
//else cout<<"X\n";
return;
}
for(int i=1;i<=n && (V[i-1][1]!=0 || i==1);i++){
V[i][1]|=(1<<k);
//cout<<V[i][1]<<'\n';
int init=V[i][2];
V[i][2]|=P[k];
bk(k+1);
V[i][2]=init;
V[i][1]-=(1<<k);
}
return;
}
int main (){
fin>>n;
for(int i=1;i<=n;i++){
V[i][1]=V[i][2]=P[i]=0;
for(int j=1;j<=n;j++){
char c;
fin>>c;
P[i]+=(c-'0')<<j;
}
}
bk(1);
fout<<pos;
return 0;
}