2189. Number of Ways to Build House of Cards

Обновлено: 2024-03-12
1 мин
[]

Содержание

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)