Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- Dictionary Search Help
- boole_d
- APPENDING CORRESPONDING
- SM36
- APPENDING
- ZPL
- batch job
- NEW-PAGE PRINT ON
- using value
- Data Browser
- cfieldname
- DP - 무한배낭
- ALV Output Setting
- MONAT_F4
- DP - 유한배낭
- 날짜 계산 함수
- java
- ABAP
- 필드카탈로그
- qfieldname
- DP - 무한배낭(순서)
- FOR ALL ENTRIES IN
- CTS #CTS 이관 #SAP #ABAP
- SAP
- BOJ_Gold
- SAP GUI
- Union-Find
- transporting
- changing value
- READ TABLE
Archives
- Today
- Total
Jin's Library
[Silver Ⅲ] 9461 - 파도반 수열 본문
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class BOJ_9461 {
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
for(int i = 0; i < N; i++){
int x = Integer.parseInt(br.readLine());
long[] dp = new long[Math.max(x+1, 6)];
dp[1] = dp[2] = dp[3] = 1;
dp[4] = dp[5] = 2;
for(int j = 6; j <= x; j++) dp[j] = dp[j-5] + dp[j-1];
sb.append(dp[x]).append("\n");
}
System.out.println(sb);
}
}
// #2 dp가 int라서 터졌다. long으로 선언해야함.
// public class BOJ_9461 {
// public static void main(String[] args) throws Exception{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// StringBuilder sb = new StringBuilder();
// int N = Integer.parseInt(br.readLine());
// for(int i = 0; i < N; i++){
// int x = Integer.parseInt(br.readLine());
// if(x == 1){
// sb.append(1).append("\n");
// continue;
// }else if(x == 2){
// sb.append(1).append("\n");
// continue;
// }else if(x == 3){
// sb.append(1).append("\n");
// continue;
// }else if(x == 4){
// sb.append(2).append("\n");
// continue;
// }else if(x == 5){
// sb.append(2).append("\n");
// continue;
// }
// int[] dp = new int[x+1];
// dp[1] = 1;
// dp[2] = 1;
// dp[3] = 1;
// dp[4] = 2;
// dp[5] = 2;
// for(int j = 6; j <= x; j++) dp[j] = dp[j-5] + dp[j-1];
// sb.append(dp[x]).append("\n");
// }
// System.out.println(sb);
// }
// }
// #1 재귀는 시간초과
// public class BOJ_9461 {
// public static void main(String[] args) throws Exception{
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// StringBuilder sb = new StringBuilder();
// int N = Integer.parseInt(br.readLine());
// for(int i = 0; i < N; i++){
// int x = Integer.parseInt(br.readLine());
// sb.append(tri(x)).append("\n");
// }
// System.out.println(sb);
// }
// public static int tri(int x){
// if(x == 1) return 1;
// else if(x == 2) return 1;
// else if(x == 3) return 1;
// else if(x == 4) return 2;
// else if(x == 5) return 2;
// else return tri(x-1) + tri(x-5);
// }
// }'Algorithm - Java > BOJ - Silver' 카테고리의 다른 글
| [Silver Ⅲ] 2579 - 계단 오르기 (0) | 2025.10.24 |
|---|---|
| [Silver Ⅲ] 9095 - 1, 2, 3 더하기 (0) | 2025.10.20 |
| [Silver Ⅳ] 4949 - 균형잡힌 세상 (0) | 2025.10.17 |
| [Sliver Ⅱ] 10799 - 쇠막대기 (0) | 2025.10.17 |
| [Silver Ⅲ] 2346 - 풍선 터뜨리기 (0) | 2025.10.01 |