Untitled

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

int map[105];
int N,K;
int ans;


void bat_tat(int k){
	for (int i = k; i <= N; i += k+1)
	{
		if (map[i] == 1)
		{
			map[i] = 0;
		}
		else
		{
			map[i] = 1;
		}
	}
}

int dem_0(){
	int dem = 0;
	for (int i = 1; i <= N; i++)
	{
		if (map[i] == 0)
		{
			dem++;
		}
	}
	return dem;
}

void backTrack(int k){
	if (dem_0() > ans)
	{
		ans = dem_0();
	}
	if (k == 3)
	{
		return;
	}

	for (int i = 1; i <= K; i++)
	{
		bat_tat(i);
		backTrack(k+1);
		bat_tat(i);
	}

}

int main(){
	freopen("input.txt","r",stdin);
	int T;
	cin>>T;
	for (int tc = 1; tc <= T; tc++)
	{
		cin>>N>>K;
		for (int i = 1; i <= N; i++)
		{
			cin>>map[i];
		}
		
		ans = 0;
 		backTrack(0);

		cout<<"#"<<tc<<" "<<ans<<endl;
	}

	return 0;
}