2xn에서 변형된 문제인거같다.
비슷하게 DP로 풀었고 좀 더 경우가 많았다.
#include <string>
#include <vector>
#define MOD 1000000007
using namespace std;
int solution(int n) {
int answer = 0;
if (n % 2 == 1)
return 0;
vector<long long> DP(n + 1);
DP[0] = 1;
DP[2] = 3;
for (int i = 4; i <= n; i += 2)
{
DP[i] = DP[i - 2] * 3;
for (int j = i - 4; j >= 0; j -= 2)
DP[i] += DP[j] * 2;
DP[i] %= MOD;
}
answer = DP[n];
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 쿼드압축 후 개수 세기 (0) | 2022.06.08 |
|---|---|
| [프로그래머스] (C++) LV2 n^2 배열 자르기 (0) | 2022.06.05 |
| [프로그래머스] (C++) LV2 점프와 순간 이동 (0) | 2022.06.04 |
| [프로그래머스] (C++) LV2 이진 변환 반복하기 (0) | 2022.06.04 |
| [프로그래머스] (C++) LV2 모음 사전 (0) | 2022.06.03 |