LeetCoed 5383. Number of schemes to color N x 3 grid

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)

 

Published 248 original articles · Like 29 · Visits 30,000+

Guess you like

Origin blog.csdn.net/weixin_38603360/article/details/105467377