CS/Algorithm
[백준 : 11726] 2 x n 타일링 - JAVA
yujindonut
2021. 5. 16. 16:27
728x90
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static Integer dp[];
public static void main(String[] args) throws Exception, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
dp = new Integer[N + 1];
System.out.println(find(N));
}
static int find(int N) {
if(N == 0 || N == 1)
return 1;
if(dp[N] == null) {
dp[N] = find(N - 2) + find(N - 1);
}
return dp[N] % 10007;
}
}
타일 몇개 그려보면 d[n] = d[n - 2] + d[n - 1] 패턴을 얻을 수 있었다!
return 할때, %10007깜빡하고 안넣어서 계속 오류남 ㅜㅜ
그전에 패턴 그대로 쓰니까 쉽게 풀렸다!
728x90