풀이 과정
다이나믹 프로그래밍의 기초 문제이다.
앞의 두 수를 더해주고, 1234567로 나눈 나머지의 값을 리턴하면 된다.
#include <string>
#include <vector>
using namespace std;
int dp[100001];
int fibo(int n){
dp[0] = 0;
dp[1] = 1;
for(int i = 2; i <= n; i++){
dp[i] = (dp[i - 1] + dp[i - 2]) % 1234567;
}
return dp[n] % 1234567;
}
int solution(int n) {
int answer = 0;
answer = fibo(n);
return answer;
}
'🍞 Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스][Level2] 거리두기 확인하기 c++ (0) | 2022.10.20 |
---|---|
[프로그래머스][Level2] N개의 최소공배수 c++ (0) | 2022.10.20 |
[프로그래머스][Level2] 큰 수 만들기 c++ (0) | 2022.10.20 |
[프로그래머스][Level2] 가장 큰 정사각형 c++ (0) | 2022.10.20 |
[프로그래머스][Level2] 삼각 달팽이 c++ (0) | 2022.10.20 |