From 614a605e813060eaed5f0619e1f89f707a3fc913 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 3 Jul 2022 16:38:32 +0800 Subject: [PATCH] =?UTF-8?q?P1441=20=E7=A0=9D=E7=A0=81=E7=A7=B0=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/78343607 --- Luogu/P1441/P1441.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Luogu/P1441/P1441.cpp diff --git a/Luogu/P1441/P1441.cpp b/Luogu/P1441/P1441.cpp new file mode 100644 index 00000000..ccd4a1b6 --- /dev/null +++ b/Luogu/P1441/P1441.cpp @@ -0,0 +1,40 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 20; + +int n, m, a[N], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 0; i < n; i++) { + cin >> a[i]; + } + + for (int i = 0; i < 1 << n; i++) { + if (__builtin_popcount(i) == n - m) { + std::bitset<2005> s; + s[0] = 1; + + for (int j = 0; j < n; j++) { + if (i & (1 << j)) { + s |= s << a[j]; + } + } + + ans = std::max(ans, (int)s.count()); + } + } + + cout << ans - 1 << endl; + + return 0; +}