题目描述
blablabla
样例
blablabla
算法1
blablabla
时间复杂度
参考文献
代码
import java.io.*;
class Main{
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static int nextInt() throws Exception{
in.nextToken();
return (int)in.nval;
}
static int[] st, ans;
static int size, n;
static void DFS(int top, int d, int cnt){
if(size >= 20) return;
if(cnt==n){
size++;
for(int i=0;i<n;i++) out.print(ans[i]);
out.println("");
return;
}
if(top>-1){
ans[cnt] = st[top];
DFS(top-1, d, cnt+1);
st[top] = ans[cnt];
}
if(d<=n){
st[top+1] = d;
DFS(top+1, d+1, cnt);
}
}
public static void main(String[] args) throws Exception{
n = nextInt();
st = new int[n+1];
ans = new int[n+1];
size = 0;
DFS(-1, 1, 0);
out.close();
}
}