2021清北學堂國慶刷題班Day1
阿新 • • 發佈:2021-10-02
比賽補題
A. elective
巨大簡單的一道題,$ n \leq 20 $ 直接 $ 2 ^ {n} $ 列舉選的情況,每次判斷是否更優並記錄即可。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<vector> #include<queue> typedef double db; using std::pair; using std::make_pair; long long n, a[25], p[25]; template <class I> inline void read(I &x){ x = 0; int f = 1; char ch; do { ch = getchar(); if(ch == '-') f = -1; } while(ch < '0' || ch > '9'); do { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } while(ch >= '0' && ch <= '9'); x *= f; return; } int main(){ read(n); for(int i = 1; i <= n; ++i) read(a[i]); for(int i = 1; i <= n; ++i) read(p[i]); long long ans = -1, now = 0; double P = 1.00; for(int i = 0; i < (1 << n); ++i){ P = 1.00, now = 0; // std::cout << i << '\n'; for(int j = 0; j < n; ++j){ if(i & (1 << j)) P *= ((double)p[j + 1] / 10.0), now += a[j + 1]; } // if(i == 9) std::cout << p << '\n'; if(P >= 0.5) ans = std::max(ans, now); } printf("%lld\n", ans); return 0; }