https://www.acmicpc.net/problem/1904
import java.io.*;
import java.util.*;
public class Main {
public static int[] memo = new int[1000001];
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
memo[1] = 1;
memo[2] = 2;
System.out.println(func(a));
}
static int func(int a) {
for(int i=3; i<=a; i++) {
memo[i] = (memo[i-2]+memo[i-1])%15746;
}
return memo[a];
}
}
Bottom-up으로 했더니 통과되었다.
'백준' 카테고리의 다른 글
백준 동적계획법 - 1149번 : RGB 거리 (1) | 2022.02.17 |
---|---|
백준 동적계획법 - 9461번 : 파도반 수열 (0) | 2022.02.16 |
백준 동적계획법 - 9184번 : 신나는 함수 실행 (0) | 2022.02.16 |
백준 동적계획법 - 1003번 : 피보나치 함수 (0) | 2022.02.16 |
백준 백트래킹 - 14889번 : 스타트와 링크 (1) | 2022.02.16 |