5383. 给 N x 3 网格图涂色的方案数
分类:ABA, ABC各6种,每个ABA可与2ABC+3ABA结合, 每个ABC可与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)