728x90
https://www.acmicpc.net/problem/2309
2309번: 일곱 난쟁이
아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.
www.acmicpc.net
import java.util.Arrays;
import java.util.Scanner;
public class Prac {
static int[] shortPeople = new int[9];
static int[] answer = new int[7];
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for(int i=0; i<shortPeople.length; i++) {
shortPeople[i] = sc.nextInt();
}
combination(0, 0);
}
static void combination(int n, int start) {
if(n==7) {
if(Arrays.stream(answer).sum()==100) {
Arrays.sort(answer);
for(int i=0; i<answer.length; i++) {
System.out.println(answer[i]);
}
}
return;
}
for(int i=start; i<shortPeople.length; i++) {
answer[n] = shortPeople[i];
combination(n+1, i+1);
}
}
}
728x90
'[알고리즘] > 알고리즘' 카테고리의 다른 글
[알고리즘] SW Expert Acadamy 5215. 햄버거 다이어트 (0) | 2022.02.17 |
---|---|
[알고리즘] 백준 1991. 트리순회 (0) | 2022.02.13 |
[알고리즘] SW Expert Academy 3499. 퍼펙트 셔플 (0) | 2022.02.13 |
[알고리즘] 백준 17478. 재귀함수가 뭔가요? (0) | 2022.02.13 |
[알고리즘] 백준 10974. 모든 순열 (0) | 2022.02.13 |