#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2001;
const int inf=1e15+7;
int v[maxn], dp[maxn][maxn]; // dp[pos][qtd], posição autal(a ser calculada, obs: suponnho q o meu geupo termina na minha posição) e qtd de grupos já divididos
void roda(int n){
int last=v[n];
for(int i=1;i<=n;i++) swap(v[i],last);
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int n, a, b; cin >> n >> a >> b;
for(int i=1;i<=n;i++) cin >> v[i];
int resp=inf;
for(int l=1;l<=n+1;l++){
roda(n);
for(int i=0;i<maxn;i++)
for(int j=0;j<maxn;j++) dp[i][j]=inf;
dp[0][0]=0;
for(int i=1;i<=n;i++){ // brutando a posição atual
int sum=0;
for(int j=i;j>=1;j--){ // brutando aonde eu vou quebrar o grupo atual
sum+=v[j];
for(int k=1;k<=i;k++){ // brutando qnts grupos já foram feitos
dp[i][k]=min(dp[i][k],(dp[j-1][k-1]|(sum)));
}
}
}
for(int i=a;i<=b;i++) resp=min(resp,dp[n][i]);
}
cout << resp << endl;
}
# | 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... |