#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll N, A, B;
vector<ll> V;
vector<vector<ll>> dp; // dp[i][OR-sum]
vector<ll> PS;
ll sum(ll a, ll b) {
return PS[b+1] - PS[a];
}
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
cin >> N >> A >> B;
V.resize(N), PS.resize(N+1);
ll UB = 0;
for(ll i = 0; i < N; i++) {
cin >> V[i];
PS[i+1] = PS[i] + V[i];
UB += V[i];
}
ll UBB = ((1ll << (__lg(UB) + 1ll)) - 1ll);
dp.resize(N+1, vector<ll>(UBB + 1, INF));
dp[0][0] = 0;
for(ll i = 0; i <= N; i++) {
for(ll k = UBB; k >= 0; k--) {
for(ll j = 0; j < i; j++) {
dp[i][sum(j, i-1) | k] = min(dp[i][sum(j, i-1) | k], 1 + dp[j][k]);
// cout << i << ' ' << j << ' ' << k << ' ' << (sum(j, i-1) | k) << ' ' << dp[j][k] << ' ' << dp[i][sum(j, i-1) | k] << endl;
}
}
}
for(ll k = 0; k <= UBB; k++) {
if (dp[N][k] <= B) {
cout << k << endl;
break;
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |