Untitled

 avatar
unknown
plain_text
2 years ago
2.0 kB
14
Indexable
// In Practice, You should use the statndard input/output
// in order to receive a score properly.
// Do not use file input and output. Please be very careful. 
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

using namespace std;
int N, K;
int arr[101];
int visited[101];
int maxDenTat;

void tat_bat_den(int khoa){
	int tmp = 0;
	for (int i = khoa; i <= N; i++)
	{
		if(i == khoa || i-tmp == khoa+1){
			tmp = i;
			arr[i] = 1-arr[i];
		}
	}
}

int so_bong_den_tat(){
	int cnt = 0;
	for (int i = 1; i <= N; i++)
	{
		if(arr[i] == 0) cnt++;
	}
	return cnt;
}

void bt(int den, int thutuden){
	
	int cnt = so_bong_den_tat();
	if(cnt > maxDenTat) maxDenTat= cnt;
	if(thutuden == 3){
		return;
	}
	for (int i = 1; i <= K; i++)
	{
		
		if(visited[i] == 0){
			//khong tat den
			visited[i] = 1;
			bt(i, thutuden+1);
			visited[i] = 0;
			//tat den
			tat_bat_den(den);
			visited[i] = 1;
			bt(i, thutuden+1);
			tat_bat_den(den);
			visited[i] = 0;
		}
	}
	
}

int main(int argc, char** argv)
{
	int test_case;
	int T;
	int Answer;

	ios::sync_with_stdio(false);

	/* 
	The freopen function below opens input.txt in read only mode and 
	sets your standard input to work with the opened file. 
	When you test your code with the sample data, you can use the function
	below to read in from the sample data file instead of the standard input.
	So. you can uncomment the following line for your local test. But you
	have to comment the following line when you submit for your scores.
	*/

//	freopen("input.txt", "r", stdin);
	cin >> T;

	/*
	Read each test case from standard input.
	*/
	for(test_case = 1; test_case <= T; ++test_case)
	{
		Answer = 0;
		cin >> N >> K;
		for (int i = 1; i <= N; i++)
		{
			cin >> arr[i];
			visited[i] = 0;
		}
		maxDenTat = 0;
		bt(1, 0);
		cout << "#" << test_case << " " << maxDenTat << endl;
	}
	return 0;//Your program should return 0 on normal termination.
}
Editor is loading...