From 6b96701ad004b64ac6ef71331dcff1e7e5cc528d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 13 Nov 2022 11:24:09 +0800 Subject: [PATCH] =?UTF-8?q?P2473=20[SCOI2008]=20=E5=A5=96=E5=8A=B1?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/93856344 --- Luogu/P2473/P2473.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Luogu/P2473/P2473.cpp diff --git a/Luogu/P2473/P2473.cpp b/Luogu/P2473/P2473.cpp new file mode 100644 index 00000000..daae2d14 --- /dev/null +++ b/Luogu/P2473/P2473.cpp @@ -0,0 +1,45 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 15 + 2, + K = 105; + +int k, n, p[N], s[N]; +double f[K][1 << N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> k >> n; + + for (int i = 1, x; i <= n; i++) { + cin >> p[i]; + + while (cin >> x, x) { + s[i] |= 1 << x - 1; + } + } + + for (int i = k; i; i--) { + for (int t = 0; t < 1 << n; t++) { + for (int j = 1; j <= n; j++) { + if ((t & s[j]) == s[j]) { + f[i][t] += std::max(f[i + 1][t], f[i + 1][t | (1 << j - 1)] + p[j]); + } else { + f[i][t] += f[i + 1][t]; + } + } + + f[i][t] /= n; + } + } + + cout << std::fixed << std::setprecision(6) << f[1][0] << endl; + + return 0; +}