diff --git "a/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" "b/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" index 747f8cd273976..187bb6c186990 100644 --- "a/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" +++ "b/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/README.md" @@ -235,6 +235,46 @@ function perfectMenu( } ``` +#### Swift + +```swift +class Solution { + func perfectMenu(_ materials: [Int], _ cookbooks: [[Int]], _ attribute: [[Int]], _ limit: Int) -> Int { + let n = cookbooks.count + var ans = -1 + + for mask in 0..<(1 << n) { + var a = 0, b = 0 + var cnt = [Int](repeating: 0, count: 5) + + for i in 0..> i & 1) == 1 { + a += attribute[i][0] + b += attribute[i][1] + for j in 0.. materials[i] { + ok = false + break + } + } + + if b >= limit && a > ans && ok { + ans = a + } + } + + return ans + } +} +``` + diff --git "a/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/Solution.swift" "b/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/Solution.swift" new file mode 100644 index 0000000000000..fdf10537d0c5e --- /dev/null +++ "b/lcp/LCP 51. \347\203\271\351\245\252\346\226\231\347\220\206/Solution.swift" @@ -0,0 +1,35 @@ +class Solution { + func perfectMenu(_ materials: [Int], _ cookbooks: [[Int]], _ attribute: [[Int]], _ limit: Int) -> Int { + let n = cookbooks.count + var ans = -1 + + for mask in 0..<(1 << n) { + var a = 0, b = 0 + var cnt = [Int](repeating: 0, count: 5) + + for i in 0..> i & 1) == 1 { + a += attribute[i][0] + b += attribute[i][1] + for j in 0.. materials[i] { + ok = false + break + } + } + + if b >= limit && a > ans && ok { + ans = a + } + } + + return ans + } +} \ No newline at end of file