[Programmers] 2 x n 타일링

Time Lapse :3min 0sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <vector>

using namespace std;


int solution(int n) {
if(n==1)
return 1;
else if(n==2)
return 2;
else{
int dp[3] = {1,1,0};
for(int i=2;i<=n;i++){
dp[i%3] = (dp[(i+1)%3] + dp[(i+2)%3]) % 1000000007;
}
return dp[n%3];
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/2xnTiling/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.