This is basically just a math question.
If we let nT(n) be the number of possible tilings of
size n, we can see that it is equal to the sum of:
This infers that the equation below holds:
Therefore, using the equation above,
meaning this is just a recursive function:
code
class Solution {
public:
int numTilings(int n) {
--n;
vector<int> count = {1, 2, 5};
if (n < 2) {
return count[n];
}
for (int i = 2; i < n; ++i) {
count.push_back(count.back()*2 + count[0]);
count.erase(count.begin());
}
return count.back();
}
};
complexity