Created
August 23, 2021 23:38
-
-
Save masakih/a6b4c4fcfbbee1093a7e058f84891ddf to your computer and use it in GitHub Desktop.
algo323
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 = [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