-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest333.java
More file actions
36 lines (31 loc) Β· 1.23 KB
/
test333.java
File metadata and controls
36 lines (31 loc) Β· 1.23 KB
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
public class test333{
static int lim = 2; // 1~100κΉμ§μ μ ν
static int n = 3; // 5κ°λ§ κ³ λ₯Έλ€.
static int count=0;
public static void main(String[] args){
int[] chosen = new int[n]; // μ νλ μ«μκ° μ μ₯λλ λ°°μ΄
// μμμ 0λΆν° μμνλ©° 0κ°λ₯Ό νμ¬ μ ννμΌλ μλμ κ°μ΄ parameter μ λ¬!
solve(chosen, 0, 0);
}
// chosenμ μ νλ μ«μκ° μ μ₯λ λ°°μ΄
// currμ νμ¬ μ«μλ₯Ό μ ννλ index
// cntλ λͺ κ°μ μ«μκ° μ νλμλμ§ νμΈ
private static void solve(int[] chosen, int curr, int cnt){
// nκ°μ μ«μλ₯Ό λ€ μ ννλ€λ©΄ μΆλ ₯ ν λ μ΄μ μ¬κ·λ₯Ό λμ§ μμμΌ νλ€!
// νμΆ μ‘°κ±΄μ μ μ!
if(cnt == n){
for(int i : chosen){
System.out.print(i + " ");
}
System.out.println(count);
return;
}
// λ°λ³΅λ¬Έμ ν΅ν΄ μ«μλ₯Ό κ³μ μ ν!
for(int i=curr+1; i <= lim; i++){
// νμ¬ μ νλ μ«μλ₯Ό μ μ₯
chosen[cnt] = i;
// λ€μ μ«μλ₯Ό μ ννκΈ° μν΄ μ¬κ· νΈμΆ
solve(chosen, curr, cnt+1);
}
}
}