import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class baekjoon15651 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer st;
static int N,M;
static int[] arr;
public static void func(int index) throws IOException{
if(index == M){
for(int i=0;i<M;i++){
bw.write(Integer.toString(arr[i])+" ");
}
bw.newLine();
return;
}
for(int i=0;i<N;i++){
arr[index]=i+1;
func(index+1);
}
}
public static void main(String args[]) throws IOException{
st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
arr = new int[M];
func(0);
bw.flush();
bw.close();
}
}
아무리 재귀함수를 공부해도 어려워서 차근차근 다시해나가고 있다.
dfs랑 백트래킹이랑 뭔차인가했더니
dfs기 백트래킹 방법중 한개였다...