790. Domino and Tromino Tiling

790. Domino and Tromino Tiling

class Solution:
    def numTilings(self, n: int) -> int:
        MOD=1e9+7
        m=max(n+1,3+1)
        dp=[0 for i in range(m)]
        dp[0]=1
        dp[1]=1
        dp[2]=2
        dp[3]=5
        for i in range(4,n+1):
            dp[i]=(dp[i-1]*2+dp[i-3])%MOD

        return int(dp[n])

LeetCode - The World's Leading Online Programming Learning Platform

要理解为什么这样是对的,看图

你可能感兴趣的:(leetcode)