2018-3
作者:
walmpooer
,
2024-03-07 22:21:51
,
所有人可见
,
阅读 23
# include<bits/stdc++.h>
using namespace std;
const int N = 30;
int n;
stack<int> st;
int res[N][N];
int path[N];
int cnt = 0;
int hh = 0;
void dfs(int u)
{
if(u == n+1)
{
stack<int> tmp = st;
int pre = hh;
while(tmp.size())
{
path[hh++] = tmp.top();
tmp.pop();
}
for(int i = 0; i<hh; i++)
res[cnt][i] = path[i];
hh = pre;
cnt++;
return;
}
if(st.size())
{
int x = st.top();
path[hh++] = x;
st.pop();
dfs(u);
hh--;
st.push(x);
}
st.push(u);
dfs(u+1);
st.pop();
}
int main()
{
cin>>n;
dfs(1);
for(int i = 0; i<cnt; i++)
{
for(int j = 0; j<n; j++)
{
cout<<char('a'+res[i][j]-1);
}
cout<<endl;
}
}