Created
August 25, 2021 03:58
-
-
Save masakih/3037e97949d04c0262807af0b7ed14e0 to your computer and use it in GitHub Desktop.
algo325
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 = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3 ] | |
| func getInt() -> Int { aa.count } | |
| func getIntArray() -> [Int] { aa } | |
| /// | |
| let n = getInt() | |
| var dp = Array<Array<Int?>>(repeating: Array<Int?>(repeating: nil, count: n), count: n) | |
| dp[0] = getIntArray() | |
| func solve(_ i: Int, _ j: Int) -> Int { | |
| if i < 0 { return 0 } | |
| if i > (n - 1) { return 0 } | |
| if j < 0 { return 0 } | |
| if j > (n - 1) { return 0 } | |
| if let k = dp[i][j] { | |
| return k | |
| } | |
| let k = (solve(i - 1, j - 1) + solve(i - 1, j) + solve(i - 1, j + 1)) % 100 | |
| dp[i][j] = k | |
| return k | |
| } | |
| print( | |
| solve(n - 1, n - 1) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment