2189. Number of Ways to Build House of Cards

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2189

class Solution:
    def houseOfCards(self, n: int) -> int:
        @cache
        def dfs(n: int, k: int) -> int:
            x = 3 * k + 2
            if x > n:
                return 0
            if x == n:
                return 1
            return dfs(n - x, k + 1) + dfs(n, k + 1)

        return dfs(n, 0)