https://www.acmicpc.net/problem/3040
9๋ช ์ค์์ 7๋ช ์ ์ฐพ๋ ๊ฒ์ด๋ฏ๋ก 9C7 -> ์กฐํฉ ๋ฌธ์ ์ด๋ค.
์กฐํฉ 7๊ฐ๋ฅผ ๋ค ์์ฑํ๊ณ ๋ฆฌํดํ๊ธฐ ์ ์ ์กฐํฉ์ ํฉ์ด 100์ด ๋๋์ง ํ์ธํด์ ์ถ๋ ฅํด์ฃผ๋ฉด ๋๋ค.
์ฝ๋
import java.util.Scanner;
public class Main {
static int[] hats;
static boolean[] visited;
static int[] result;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
hats = new int[9];
for(int i = 0; i < 9; i++) {
hats[i] = sc.nextInt();
}
visited = new boolean[9];
result = new int[7];
combination(0, 0);
}
public static void combination(int start, int depth) {
if(depth == 7) {
int sum = 0;
for(int n : result) {
sum += n;
}
if(sum == 100) {
for(int n : result) {
System.out.println(n);
}
}
return;
}
for(int i = start; i < 9; i++) {
if(visited[i]) continue;
visited[i] = true;
result[depth] = hats[i];
combination(i + 1, depth + 1);
visited[i] = false;
}
}
}
๊ฒฐ๊ณผ
'Algorithm > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 17406๋ฒ - ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ 4 (0) | 2022.08.11 |
---|---|
1213๋ฒ - ํฐ๋ฆฐ๋๋กฌ ๋ง๋ค๊ธฐ (0) | 2022.08.11 |
๋ฐฑ์ค 16922๋ฒ - ๋ก๋ง ์ซ์ ๋ง๋ค๊ธฐ (0) | 2022.08.11 |
๋ฐฑ์ค 16926๋ฒ : ๋ฐฐ์ด ๋๋ฆฌ๊ธฐ 1 (0) | 2022.08.09 |
2304๋ฒ - ์ฐฝ๊ณ ๋ค๊ฐํ (0) | 2022.08.09 |