[InterviewBit] Tiling With Dominoes

Tiling With Dominoes

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
int Solution::solve(int n) {
vector<long long> A(n + 1), B(n + 1);
const int mod = 1e9 + 7;
A[0] = 1, A[1] = 0, B[0] = 0, B[1] = 1;
for (int i = 2; i <= n; i++) {
A[i] = A[i - 2] + 2 * B[i - 1];
B[i] = A[i - 1] + B[i - 2];
A[i] %= mod;
B[i] %= mod;
}

return A[n];
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/04/PS/interviewbit/tiling-with-dominoes/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.