공부기록/백준

[백준] 15652번 N과 M(4)

메델 2023. 9. 27. 19:58
import java.util.Scanner;

public class Main {
	static StringBuilder sb = new StringBuilder();
	static int N, M;
	static int[] select;
	
	static void rec_func(int k) {
		if(k == M+1) {
			for(int i=1; i<=M; i++) {
				sb.append(select[i]).append(' ');
			}
			sb.append('\n');
		}else {
			int start = select[k-1];
			if(start == 0) {
				start = 1;
			}
			
			for(int j=start; j<=N; j++) {
				select[k] = j;
				rec_func(k+1);
				select[k] = 0;
				
			}
		}
	}
	
	
	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		N = kb.nextInt();
		M = kb.nextInt();
		
		select = new int[N+1];
		
		rec_func(1);
		System.out.print(sb);
		
	}
}