Skip to content

Commit facb75d

Browse files
committed
[Silver III] Title: 1, 2, 3 더하기, Time: 92 ms, Memory: 14128 KB -BaekjoonHub
1 parent 1606d90 commit facb75d

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

백준/Silver/9095. 1, 2, 3 더하기/1, 2, 3 더하기.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.util.*;
44

55
public class Main {
6-
private static int count = 0;
7-
86
public static void main(String[] args) throws Exception {
97
// System.setIn(new FileInputStream("input.txt")); // 제출 시 이 줄만 주석처리
108
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
@@ -13,25 +11,21 @@ public static void main(String[] args) throws Exception {
1311
for (int i = 1; i <= T; i++) {
1412
int target = Integer.parseInt(br.readLine());
1513

16-
count = 0;
17-
dfs(1, target);
18-
dfs(2, target);
19-
dfs(3, target);
20-
System.out.println(count);
14+
int result = dfs(1, target) + dfs(2, target) + dfs(3, target);
15+
System.out.println(result);
2116
}
2217
}
2318

24-
public static void dfs(int sum, int target) {
19+
//sum에서 Target까지 가는 방법의 수
20+
public static int dfs(int sum, int target) {
2521
if (sum > target) {
26-
return;
22+
return 0;
2723
}
2824
if (sum == target) {
29-
count++;
30-
return;
25+
return 1;
3126
}
3227

33-
dfs(sum + 1, target);
34-
dfs(sum + 2, target);
35-
dfs(sum + 3, target);
28+
//1을 선택했을 때 target까지 가는 방법의 수 + 2을 선택했을 때 target까지 가는 방법의 수 + 3을 선택했을 때 target까지 가는 방법의 수
29+
return dfs(sum + 1, target) + dfs(sum + 2, target) + dfs(sum + 3, target);
3630
}
3731
}

백준/Silver/9095. 1, 2, 3 더하기/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 14100 KB, 시간: 104 ms
7+
메모리: 14128 KB, 시간: 92 ms
88

99
### 분류
1010

1111
다이나믹 프로그래밍
1212

1313
### 제출 일자
1414

15-
2026년 1월 13일 21:26:50
15+
2026년 1월 13일 21:42:46
1616

1717
### 문제 설명
1818

0 commit comments

Comments
 (0)