5383. Number of schemes to color N x 3 grid
Classification: 6 kinds of ABA and ABC, each ABA can be combined with 2ABC + 3ABA, each ABC can be combined with 2ABC + 2ABA
class Solution:
def numOfWays(self, n: int) -> int:
same, diff = 6, 6 # 代表初始时第一行两类各6种
for k in range(1, n):
same, diff = same * 3 + diff * 2, same * 2 + diff * 2
return (same + diff) % (10 ** 9 + 7)