Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
809 B
0
Indexable
Never
#include<iostream>
using namespace std;


int N,K;
int ans;
int trangthai[101];
int dem()
{
	int temp=0;
	for(int i=1;i<=N;i++){
	if(trangthai[i]==0)
		temp++;
	}
	return temp;
}
void thaydoi_trangthai(int k)
{
	int temp=0;
	int n=0;
	while(temp<=N)
	{
		temp = k+n*(k+1);
		n++;
		if(trangthai[temp]==0)
			trangthai[temp]=1;
		else
			trangthai[temp]=0;
	}
}
void backtrack(int k)
{
	int temp=dem();
	ans=max(ans,temp);
	if(k==4)
	{
		return;
	}
	for(int i=1;i<=K;i++)
	{
	thaydoi_trangthai(i);
	backtrack(k+1);
	thaydoi_trangthai(i);
	}
}
int main()
{
  int T;
  cin>>T;
  for(int tc=1;tc<=T;tc++)
  {
	      cin>>N>>K;
	  for(int i=1;i<=N;i++)
		  cin>>trangthai[i];

	  ans=0;
	  backtrack(1);
	  cout<<"#"<<tc<<" "<<ans<<endl;
  }
	return 0;
}