790: Domino-and-Tromino-Tiling
Medium
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;
<int> count = {1, 2, 5};
vectorif (n < 2) {
return count[n];
}
for (int i = 2; i < n; ++i) {
.push_back(count.back()*2 + count[0]);
count.erase(count.begin());
count}
return count.back();
}
};