반응형
문제
https://www.acmicpc.net/problem/11726
JAVA 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
/**
* n: out
* 1: 1
* 2: 2
* 3: 3
* 4: 5
* 5: 8
* dp[n] = dp[n-1] + dp[n-2]
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
int[] dp = new int[1001];
dp[1] = 1;
dp[2] = 2;
for (int idx = 3; idx <= n; idx++) {
dp[idx] = (dp[idx - 1] + dp[idx - 2]) % 10007;
}
bw.write(String.valueOf(dp[n]));
br.close();
bw.flush();
bw.close();
}
}
반응형
'Algorithm > 문제 풀이' 카테고리의 다른 글
[BAEKJOON_14503 -JAVA] 로봇 청소기 (0) | 2023.06.16 |
---|---|
[BAEKJOON_15723 - JAVA] n단 논법 (0) | 2023.06.16 |
[BAEKJOON_17615 - JAVA] 볼 모으기 (0) | 2022.12.07 |
[BAEKJOON_12865 - JAVA] 평범한 배낭 (0) | 2022.11.24 |
[BAEKJOON_26042 - JAVA] 식당 입구 대기 줄 (0) | 2022.11.24 |