본문 바로가기

코딩테스트(백준)

[백준] 15650 : N과M(2) - JAVA(자바) - 사좋배 공유


import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static int number;
	static int size;
	static ArrayList arr;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		arr= new ArrayList();
		number = sc.nextInt();
		size = sc.nextInt();
		int index=1;
		recul(index);
	}
	private static void recul(int index) {
		if(arr.size()==size) {
			for(int i=0;i<arr.size();i++) {
				System.out.print(arr.get(i)+" ");
			}
			System.out.println();
			return;
		}
		for(int i=index;i<=number;i++) {
			arr.add(i);
			recul(i+1);
			arr.remove(arr.size()-1);
		}
	}

}