dp를 풀 때는 점화식을 구한다.
11726
11727
+) 숫자가 매우 커지니 dp[n] 을 구할 때, 10007로 나눈 나머지를 저장한다.
11726
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
int[] dp = new int[1001];
dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= n; i++) {
dp[i] = (dp[i - 1] + dp[i - 2]) % 10007;
}
System.out.print(dp[n]);
}
}
11727
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int n;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
int[] dp = new int[1001];
dp[1] = 1;
dp[2] = 3;
for (int i = 3; i <= n; i++) {
dp[i] = (dp[i - 1] + 2 * dp[i - 2]) % 10007;
}
System.out.println(dp[n]);
}
}