Untitled
user_1164828
plain_text
a year ago
918 B
12
Indexable
//Little Elephants
#include<iostream>
using namespace std;
int oo = 2000000000;
int n,k,m;
int r[20];
int ans;
bool check(){
for(int i=0; i< n-k+1; i++){
int max = 0;
for(int j=i; j < i + k; j++){
max = (r[j] > max ? r[i] : max);
}
int cnt = 0;
for(int j=i; j < i + k; j++){
if(max == r[j]) cnt++;
if(cnt == m) return false;
}
}
return true;
}
void BT(int index, int cnt){
if(cnt >= ans) return;
if(index == n){
if(check()){
if(ans > cnt){
ans = cnt;
}
}
return;
}
for(int i = 0; i<2; i++){
if(i==0){
BT(index+1,cnt);
}
else{
r[index]+=1;
BT(index+1,cnt+1);
r[index]-=1;
}
}
}
int main(){
freopen("Text.txt", "r", stdin);
int T;
cin >> T;
for(int tc=1; tc<=T; tc++){
cin >> n >> k >> m;
for(int i=0; i<n; i++){
cin >> r[i];
}
ans = oo;
BT(0,0);
if(ans == oo) ans =-1;
cout << "#" << tc << " " << ans << endl;
}
return 0;
}Editor is loading...
Leave a Comment