https://www.acmicpc.net/problem/2193
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
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());
long[][] dp = new long[N+1][2];
dp[1][0] = 0;
dp[1][1] = 1;
for (int i = 2; i <= N; i++) {
dp[i][0] = dp[i-1][0]+dp[i-1][1];
dp[i][1] = dp[i-1][0];
}
long result = dp[N][0]+dp[N][1];
bw.write(result+"\n");
br.close();
bw.flush();
bw.close();
}
}
'문제풀이 > 백준' 카테고리의 다른 글
[BOJ 10942] 팰린드롬? (0) | 2018.07.17 |
---|---|
[BOJ 1149] RGB거리 (0) | 2018.03.16 |
[BOJ 1920] 수 찾기 (0) | 2017.12.17 |
[BOJ 1708] 볼록 껍질 (0) | 2017.12.09 |