Untitled
unknown
plain_text
2 years ago
1.6 kB
5
Indexable
#include<iostream>
using namespace std;
int T,N,K,a[1001],key[1001],res,a2[1001];
void out(){
for (int i=1 ;i<=K;i++){
cout<<key[i]<<" ";
}
cout<<endl;
}
void tinh(int k){
int count=0;
for (int i=1;i<=N;i++){
if(a[i]==0){
count+1;
}
}
if(count>res)
res=count;
}
void reset2(){
for (int i=0;i<=N;i++){
a[i]=a2[i];
}
}
void switchK(){
for(int i=1;i<=N;i++){
int k=key[i];
if(k>0){
for (int j=0;j<=N;j++){
int index=k+(k+1)*j;
if(index>0&&index<=N){
if(a[index]==0) a[index]=1;
else if(a[index]==1) a[index]=0;
}
else break;
}
}
}
int count=0;
for (int i=1;i<=N;i++){
if(a[i]==0){
count++;
}
}
if(count>res)
res=count;
reset2();
}
void tohop1(int x){
for (int i=key[x-1]+1;i<=K-1+x;i++){
key[x]=i;
if(x==1){
//out();
switchK();
}
else tohop1(x+1);
}
}
void tohop2(int x){
for (int i=key[x-1]+1;i<=K-2+x;i++){
key[x]=i;
if(x==2){
//out();
switchK();
}
else tohop2(x+1);
}
}
void tohop3(int x){
for (int i=key[x-1]+1;i<=K-3+x;i++){
key[x]=i;
if(x==3){
//out();
switchK();
}
else tohop3(x+1);
}
}
void reset(){
for (int i=0;i<=N;i++){
key[i]=0;
}
}
int main(){
// freopen("input1.txt","r",stdin);
cin>>T;
for (int t=1;t<=T;t++){
cin>>N>>K;
reset();
res=0;
for (int i=1;i<=N;i++){
cin>>a2[i];
a[i] = a2[i];
if(a[i]==0) {
res++;
}
}
tohop1(1);
tohop2(1);
tohop3(1);
cout<<"#"<<t<<" "<<res<<endl;
}
return 0;
}Editor is loading...
Leave a Comment