#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int MAXN = 101;
const int MAXV = 20;
const int INF = 1e9;
int dp[MAXN][MAXN*MAXV];
int arr[MAXN];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n, l, r; cin >> n >> l >> r;
int k = r;
for (int i=1; i<=n; i++) cin >> arr[i];
for (int i=1; i<=n*MAXV; i++) dp[0][i] = INF;
dp[0][0] = 0;
for (int i=1; i<=n; i++) {
for (int cost=0; cost<=i*MAXV; cost++) {
dp[i][cost] = INF;
int sum = 0;
for (int j=i; j>=1; j--) {
sum += arr[j];
for (int lastCost=0; lastCost<=(j-1)*MAXV; lastCost++) {
if ((lastCost | sum) != cost) continue;
dp[i][cost] = min(
dp[i][cost],
dp[j-1][lastCost] + 1
);
}
}
}
}
for (int cost=0; cost<=n*MAXV; cost++) {
if (dp[n][cost] <= k) {
cout << cost << '\n';
break;
}
}
return 0;
}
| # | 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... |