# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
742317 | viwlesxq | Bali Sculptures (APIO15_sculpture) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef string str;
const int N = 101;
const int R = 21;
const int Y = 501;
const ll inf = 1e18;
ll y[N], pref[N];
bool dp[N][R][Y];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, a, b;
cin >> n >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> y[i];
pref[i] = pref[i - 1] + y[i];
}
for (int i = 1; i <= n; ++i) {
dp[i][1][pref[i]] = true;
}
for (int k = 2; k <= b; ++k) {
for (int i = 1; i <= n; ++i) {
for (int j = i - 1; j >= 1; --j) {
for (int x = 0; x < Y; ++x) {
if (dp[j][k - 1][x]) {
dp[i][k][x | (pref[i] - pref[j])] = true;
}
}
}
}
}
ll ans = inf;
for (int k = a; k <= b; ++k) {
for (int x = 0; x < Y; ++x) {
if (dp[n][k][x]) {
ans = min(ans, 1ll * x);
}
}
}
cout << ans;
}