P6183 [USACO10MAR] The Rock Game S
#include<bits/stdc++.h>
using namespace std;
int n;bool vis[100];
char a[100];
void f(int x)
{
vis[x]=1;
for(int i=n-1;i>=0;i--)
{
if((x>>i&1))
cout<<'X';
else
cout<<'O';
}
cout<<endl;
}
void dfs(int t,int x)
{
if(!vis[x])
f(x);
if(t==(1<<n)+1)
return;
for(int i=0;i<n;i++)
{
int nw=x^(1<<i);
if(!vis[nw])
{
dfs(t+1,nw);
}
}
}
int main()
{
cin>>n;
dfs(1,0);
for(int i=1;i<=n;i++)
cout<<'O';
return 0;
}