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;
}