Created
August 24, 2021 22:45
-
-
Save masakih/47caec1a1c2b9ac9b61c84cc3592cb08 to your computer and use it in GitHub Desktop.
algo324
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let aa = [0, 2, 7, 8] | |
| func getIntArray() -> [Int] { aa } | |
| /// | |
| var dp = Array<Array<Int?>>(repeating: Array<Int?>(repeating: nil, count: 4), count: 4) | |
| dp[0] = getIntArray() | |
| func solve(_ n: Int, _ m: Int) -> Int { | |
| if n < 0 { return 0 } | |
| if n > 3 { return 0 } | |
| if m < 0 { return 0 } | |
| if m > 3 { return 0 } | |
| if let k = dp[n][m] { | |
| return k | |
| } | |
| let k = solve(n - 1, m - 1) + solve(n - 1, m) + solve(n - 1, m + 1) | |
| dp[n][m] = k | |
| return k | |
| } | |
| print( | |
| solve(3, 3) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment