BOJ_B2_3040
π [B2_3040] λ°±μ€ κ³΅μ£Όμ μΌκ³± λμμ΄
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int[] arr;
// 7κ° λ½κΈ°
static int[] num;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
// μΌκ³± λμμ΄ λ°°μ΄
arr = new int[9];
num = new int[7];
// μ
λ ₯
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(br.readLine());
}
dfs(0, 0);
}
// μ‘°ν©
static void dfs(int cnt, int start) {
if (cnt == 7) {
int sum = 0;
// sum ꡬνκΈ°
for (int i = 0; i < num.length; i++) {
sum += num[i];
}
if (sum == 100) {
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
return;
}
return;
}
// λ€μ κ² λΆν° μμ±
for (int i = start; i < arr.length; i++) {
num[cnt] = arr[i];
dfs(cnt + 1, i + 1);
}
}
}
π€ λμ μκ°
보μλ§μ μμκ° μκ΄μλ κ³μ°μ΄λΌκ³ μκ°νμ¬ μ‘°ν©μΌλ‘ νμ΄μ£Όμλ€.
κ·Έλ¬λ μ½κ² ν΄κ²°νμ§ λͺ»νμ¬ ν λ²λ μ‘°ν©μ λλΌκ² λλ λ¬Έμ μλ€.
μμλλ‘ λμμ΄λ€μ κ°μ λ°μμ λ°°μ΄μ μ μ₯ν λ€ 7λͺ
μ΄ λλ©΄ ν©μ ꡬνκ³ κ·Έ ν©μ΄ 100μ΄ λλ€λ©΄ λ°λ‘ λμμ΄λ€μ μΆλ ₯, 100μ΄ μλλ€λ©΄ 리ν΄ν΄μ£Όμλ€.