可以发现,第一个字符必须是 。
然后,之后每一个字符不能大于之前出现的字符 。
可以使用反证法,如果大于最大值 那么可以用最大值代替。
综上,直接 dfs 一次得出答案即可。
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
re int t=0;
re char v=getchar();
while(v<'0')v=getchar();
while(v>='0'){
t=(t<<3)+(t<<1)+v-48;
v=getchar();
}
return t;
}
long long a;
char s[12];
inline void dfs(re int x,re char c){
if(x==a+1){
printf("%s\n",s+1);
return;
}
for(re int i='a';i<=min(c,'z');++i){
s[x]=i;
if(i!=c)dfs(x+1,c);
else dfs(x+1,c+1);
}
}
int main(){
a=read();
dfs(1,'a');
}