백준/동적 계획법
[백준] 1904 - 01 타일 [JAVA]
odong2
2024. 4. 24. 17:01

코드
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
static int[] dp = new int[1000001];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
dp[1] = 1;
dp[2] = 2;
System.out.println(solution(N));
}
static int solution(int n) {
if (dp[n] == 0) {
dp[n] = (solution(n - 1) + solution(n - 2)) % 15746;
}
return dp[n];
}
}