728x90
๐๋ฌธ์ ๋ณด๋ฌ๊ฐ๊ธฐ
๐จ๐ปํ์ด ์ ๋ต
์ ๋ ฅ ๋ฐ์ดํฐ ๋ฒ์๊ฐ ์ต๋ 10๋ง ์ธ ๊ฑธ ๊ณ ๋ คํ๋ฉด, ์ฌ๊ท๋ก๋ ์ ๋ ๋ชป ๊ตฌํ๋ DP(Dynamic Programming)์ผ๋ก ํ์์ต๋๋ค. 1234567๋ก ๋๋ ๋๋จธ์ง๋ฅผ ๋ฆฌํดํ๋ผ๋ ๊ฑธ๋ก ๋ณด์, ์ค๋ฒํ๋ก์ฐ๋ฅผ ์กฐ์ฌํด์ผ๊ฒ ๋ค๊ณ ์๊ฐํ๊ตฌ์.
โ๏ธ์์ค ์ฝ๋ ๋ฐ ๊ฒฐ๊ณผ
#include <vector>
using namespace std;
const int DIVISION = 1234567;
int solution(int n) {
vector<int> F(n + 1);
F[0] = 0;
F[1] = 1;
for (int i = 2; i <= n ; i++)
F[i] = (F[i-1] + F[i-2]) % DIVISION;
return F[n];
}
728x90
๋ฐ์ํ
'๐คAlgorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] Lv2. ๊ตฌ๋ช ๋ณดํธ | C++ (0) | 2023.06.13 |
---|---|
[Programmers] Lv2. ์ง์ง์ด ์ ๊ฑฐํ๊ธฐ | C++ (0) | 2023.06.12 |
[Programmers] Lv2. ์ด์ง ๋ณํ ๋ฐ๋ณตํ๊ธฐ | C++ (0) | 2023.06.12 |
[Programmers] Lv2. ์ซ์์ ํํ | C++ (0) | 2023.06.12 |
[Programmers] Lv2. ์ต์๊ฐ ๋ง๋ค๊ธฐ | C++ (1) | 2023.06.11 |