diff --git a/lcp/LCP 51. 烹饪料理/README.md b/lcp/LCP 51. 烹饪料理/README.md index 747f8cd273..187bb6c186 100644 --- a/lcp/LCP 51. 烹饪料理/README.md +++ b/lcp/LCP 51. 烹饪料理/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. 烹饪料理/Solution.swift b/lcp/LCP 51. 烹饪料理/Solution.swift new file mode 100644 index 0000000000..fdf10537d0 --- /dev/null +++ b/lcp/LCP 51. 烹饪料理/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