Skip to content

Instantly share code, notes, and snippets.

@masakih
Created August 23, 2021 23:38
Show Gist options
  • Select an option

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

Select an option

Save masakih/a6b4c4fcfbbee1093a7e058f84891ddf to your computer and use it in GitHub Desktop.
algo323
let aa = [696, 300, 458, 384, 75, 431, 353, 626, 219, 941, 46, 816, 724, 361]
func getInt2() -> (Int, Int) { (899, 14) }
func getIntArray() -> [Int] { aa }
///
let (n, m) = getInt2()
let a = getIntArray()
var dp = Array<Bool?>(repeating: nil, count: n + 1)
dp[0] = true
func solve(_ n: Int) -> Bool {
if let k = dp[n] {
return k
}
let r = a
.lazy
.filter { n - $0 >= 0 }
.contains { solve(n - $0) }
dp[n] = r
return r
}
print(
solve(n) ? "Yes" : "No"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment