Skip to content

Commit e8878df

Browse files
committed
[Silver III] Title: 파도반 수열, Time: 196 ms, Memory: 18464 KB -BaekjoonHub
1 parent 1e67573 commit e8878df

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# [Silver III] 파도반 수열 - 9461
2+
3+
[문제 링크](https://www.acmicpc.net/problem/9461)
4+
5+
### 성능 요약
6+
7+
메모리: 18464 KB, 시간: 196 ms
8+
9+
### 분류
10+
11+
다이나믹 프로그래밍, 수학
12+
13+
### 제출 일자
14+
15+
2025년 5월 2일 02:41:43
16+
17+
### 문제 설명
18+
19+
<p><img alt="" src="https://www.acmicpc.net/upload/images/pandovan.png" style="float:right; height:182px; width:289px">오른쪽 그림과 같이 삼각형이 나선 모양으로 놓여져 있다. 첫 삼각형은 정삼각형으로 변의 길이는 1이다. 그 다음에는 다음과 같은 과정으로 정삼각형을 계속 추가한다. 나선에서 가장 긴 변의 길이를 k라 했을 때, 그 변에 길이가 k인 정삼각형을 추가한다.</p>
20+
21+
<p>파도반 수열 P(N)은 나선에 있는 정삼각형의 변의 길이이다. P(1)부터 P(10)까지 첫 10개 숫자는 1, 1, 1, 2, 2, 3, 4, 5, 7, 9이다.</p>
22+
23+
<p>N이 주어졌을 때, P(N)을 구하는 프로그램을 작성하시오.</p>
24+
25+
### 입력
26+
27+
<p>첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, N이 주어진다. (1 ≤ N ≤ 100)</p>
28+
29+
### 출력
30+
31+
<p>각 테스트 케이스마다 P(N)을 출력한다.</p>
32+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.*;
2+
3+
public class Main {
4+
static long[] DP = new long[101];
5+
6+
public static void main(String[] args) {
7+
Scanner sc = new Scanner(System.in);
8+
StringBuilder sb = new StringBuilder();
9+
10+
DP[1] = 1;
11+
DP[2] = 1;
12+
DP[3] = 1;
13+
DP[4] = 2;
14+
DP[5] = 2;
15+
16+
int T = sc.nextInt();
17+
for(int i=0; i<T; i++){
18+
int N = sc.nextInt();
19+
20+
for(int j=1; j<=N; j++){
21+
if(DP[j] == 0){
22+
DP[j] = DP[j-1] + DP[j-5];
23+
}
24+
}
25+
sb.append(DP[N] + "\n");
26+
}
27+
28+
System.out.println(sb);
29+
}
30+
}

0 commit comments

Comments
 (0)