Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
952 B
51
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

using namespace std;

int N, K;
int state[105];

int ans;

void action(int key) {
	int n = 0;
	int k = key + 1;
	while ((k + n*(k+1)) <= N) {
		state[k + n*(k+1)] = 1 - state[k + n*(k+1)];
		n++;
	}
}

void backTrack(int k, int time) {
	if (k == K || time == 3) {
		int cnt = 0;
		for (int i = 1; i <= N; i++)
			if (!state[i])
				cnt++;

		if (cnt >  ans)
			ans = cnt;
		return;
	}

	for (int i = 0; i < 2; i++) {
		if (i == 0) {
			backTrack(k + 1, time);
		} else {
			action(k);
			backTrack(k + 1, time + 1);
			action(k);
		}
	}
}

int main() {
	int T;
	//freopen("sample_input.txt", "r", stdin);
	cin >> T;

	for (int test_case = 1; test_case <= T; ++test_case) {
		cin >> N >> K;

		for (int i = 1; i <= N; i++)
			cin >> state[i];

		ans = 0;
		backTrack(0, 0);

		cout << "#" << test_case << " " << ans << endl;
	}
	return 0;
}