728x90
반응형
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static int N, R, sum; static int[] input, numbers; // static String str = "8\r\n" + // "6\r\n" + // "5\r\n" + // "1\r\n" + // "37\r\n" + // "30\r\n" + // "28\r\n" + // "22\r\n" + // "36"; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // br = new BufferedReader(new StringReader(str)); StringBuilder sb = new StringBuilder(); StringTokenizer st; N = 9;// 9명의 난쟁이 R = 7;// 원래 난쟁이 input = new int[N]; numbers = new int[R]; for (int i = 0; i < N; i++) { input[i] = Integer.parseInt(br.readLine()); } // System.out.println(Arrays.toString(input));// 확인 sum=0; combination(0, 0); } public static void combination(int cnt, int start) { if (cnt == R) { // System.out.println(Arrays.toString(numbers));//확인 int sum=0; for(int i=0;i<numbers.length;i++) { sum+=numbers[i]; // System.out.println(sum);//확인 } if(sum==100) { for(int i=0;i<numbers.length;i++) { System.out.println(numbers[i]); } } return; } for (int i = start; i < N; i++) { numbers[cnt] = input[i]; combination(cnt + 1, i + 1); } } } | cs |
728x90
반응형
'알고리즘 > 백준' 카테고리의 다른 글
[백준]14969_딱지놀이 (0) | 2022.02.15 |
---|---|
[백준]16935_배열돌리기3 (1) | 2022.02.09 |
[백준]16926_배열돌리기1 (0) | 2022.02.09 |
백준-10430번-java-나머지 (0) | 2021.06.08 |
백준-10869번-java-사칙연산 (0) | 2021.06.08 |