728x90
๋ฌธ์
https://www.acmicpc.net/problem/1309
๋ฐฑ์ค์ ์คํฐ์ปค๋ 2*n ํ์ผ๋ง ๋ฌธ์ ์ ๋งค์ฐ ๋น์ท...
์ฐธ๊ณ ์ฌ์ง
์ฝ๋
#include <iostream>
using namespace std;
void DP_function(int);
const int MAX_SIZE = 100000;
const int MOD = 9901;
int dp[MAX_SIZE][3];
int main() {
int column = 0;
cin >> column;
DP_function(column);
}
void DP_function(int column) {
dp[1][0] = 1;
dp[1][1] = 1;
dp[1][2] = 1;
for (int i = 2; i <= column; i++) {
//i-1๋ฒ์งธ ์ค์ ์ฌ์๊ฐ ์๋ ๊ฒฝ์ฐ
dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] + dp[i-1][2]) % MOD;
//i-1๋ฒ์งธ ์ค ์ผ์ชฝ์ ์ฌ์๊ฐ ์๋ ๊ฒฝ์ฐ
dp[i][1] = (dp[i - 1][0] + dp[i - 1][2]) % MOD;
//i-1๋ฒ์งธ ์ค ์ค๋ฅธ์ชฝ์ ์ฌ์๊ฐ ์๋ ๊ฒฝ์ฐ
dp[i][2] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
}
cout << (dp[column][0] + dp[column][1] + dp[column][2]) % MOD;
}
728x90
'๐ Coding Test Study > Algorithm Problem' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++][ํ๋ก๊ทธ๋๋จธ์ค] ๊ดํธ ๋ณํ (0) | 2021.08.22 |
---|---|
[C++][Baekjoon] 14503๋ฒ ๋ก๋ด ์ฒญ์๊ธฐ (0) | 2021.08.22 |
[C++][Baekjoon] 16974๋ฒ ์์ธ ์งํ์ฒ 2ํธ์ (0) | 2021.08.22 |
[C++][BAEKJOON][Dijkstra Alg] 1261๋ฒ ์๊ณ ์คํ (0) | 2021.08.22 |
[C++][ํ๋ก๊ทธ๋๋จธ์ค][2021 ์นด์นด์ค ์ฑ์ฉ์ฐ๊ณํ ์ธํด์ญ] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2021.08.22 |