Notice
Recent Posts
Recent Comments
07-01 02:16
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

Byeol Lo

N15651 - N과 M (3) 본문

Algorithm/Backtracking

N15651 - N과 M (3)

알 수 없는 사용자 2024. 6. 15. 22:33

import java.io.*;
import java.util.*;

public class Main {
    final static BufferedWriter BW = new BufferedWriter(new OutputStreamWriter(System.out));
    final static StringBuffer sb = new StringBuffer();
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
        solution(1, sc.nextInt(), sc.nextInt(), "");
        BW.write(sb.toString());
        BW.close();
    }

    public static void solution(int from, int to, int m, String s) {
        if (m == 1) {
            for (int i = from; i <= to; i++)
                sb.append(s + i + "\n");
        } else {
            for (int i = from; i <= to; i++)
                solution(from, to, m - 1, s + i + " ");
        }
    }
}

'Algorithm > Backtracking' 카테고리의 다른 글

N15652 - N과 M (4)  (0) 2024.06.15
N15650 - N과 M (2)  (0) 2024.06.15
Comments