• 문제 링크
7515번: Prehistoric Operating Systems
It is the year 2254. Ohio Smith is a specialist in dealing with ancient operating systems. For research purposes, he tries to install several operating systems on his computer which were used about 250 years ago. Prior research has yielded the result that
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int[] cache = new int[41];
cache[0] = 1;
cache[1] = 2;
for (int i = 2; i < 41; i++) cache[i] = cache[i - 1] + cache[i - 2];
int t = read();
for (int i = 1; i <= t; i++)
sb.append("Scenario ").append(i).append(":\n").append(cache[read()]).append("\n\n");
bw.write(sb.toString());
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}'Problem Solving > Baekjoon' 카테고리의 다른 글
| [백준] 29994 Investigating Zeroes and Ones - Dynamic Programming / Java (0) | 2024.02.21 |
|---|---|
| [백준] 14767 Flow Shop - Dynamic Programming / Java (0) | 2024.02.20 |
| [백준] 26948 Plankan - Dynamic Programming / Java (0) | 2024.02.18 |
| [백준] 8582 Park - Dynamic Programming / Java (0) | 2024.02.17 |
| [백준] 6092 Strange Towers of Hanoi - Dynamic Programming / Java (0) | 2024.02.16 |
댓글