Skip to content

Instantly share code, notes, and snippets.

@masakih
Created August 25, 2021 03:58
Show Gist options
  • Select an option

  • Save masakih/3037e97949d04c0262807af0b7ed14e0 to your computer and use it in GitHub Desktop.

Select an option

Save masakih/3037e97949d04c0262807af0b7ed14e0 to your computer and use it in GitHub Desktop.
algo325
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