[BOJ] 2133 타일 채우기

Time Lapse :NONE

2133.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>

using namespace std;

#define MAXSIZE 1000

int N;
vector<int> cells;
int cache[31];
int ans;

int dp(int idx)
{
int &ret = cache[idx];
if(ret!=-1)
return ret;

ret = 3*dp(idx-2);
for(int i=idx-4;i>=0;i-=2)
{
ret += 2*dp(i);
}
return cache[idx];
}
int main(void)
{
cin>>N;
if(N%2==1)
{
cout<<"0"<<endl;
return 0;
}
memset(cache,-1,sizeof(cache));
cache[0]=1;
cache[1]=0;
cache[2]=3;
ans = dp(N);
cout<<ans<<endl;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2133/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.