Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
767 B
1
Indexable
Never
#include<iostream>
using namespace std;
int SoBong, SoKhoa;
int den[105];
int ans; 
int dem(){
	int cnt =0;
	for(int i = 1; i <= SoBong; i++){
		if(den[i] == 0) cnt ++;
	}
	return cnt;
}
void dao(int k){
	for(int i = k; i <= SoBong; i +=k+1){
		den[i] = 1 - den[i];
	}
}

void backtrack(int i){
	int cnt = dem();
	if(ans < cnt ) ans = cnt;
	if( i == 4 ) return;
	for(int k = 1; k <= SoKhoa; k++){
		dao(k);
		backtrack(i+1);
		dao(k);
	}
}


int main(){
	//freopen("text.txt", "r", stdin);
	int test;
	cin >> test;
	for(int tc = 1; tc <= test; tc++){
		cin >> SoBong >> SoKhoa;
		for(int i = 1; i <= SoBong; i++){
			cin >> den[i];
		}
		ans = 0;
		backtrack(1);
		cout << "#" << tc << " " << ans << endl;
	 }
	 return 0;
}