- N과 M (4)
문제출처 : https://www.acmicpc.net/problem/15652
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 baekjoon15652 {
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 n,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=n;i<=N;i++){
arr[index]=i;
func(arr[index],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(1,0);
bw.flush();
bw.close();
}
}