Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
3
Indexable
Never
#include <iostream>

using namespace std;

int n, m, k;
int maxxl = 0, maxxc = 0;
int data[1005][1005];

void backtrack(int kk, int doi) {
	if (doi > k) {
		return;
	}

	if (kk > m ) {
		return;
	}

	if ((k-doi) % 2 == 0 ) {
       int dem = 0;
	   for (int i = 0; i < n; i++) {
		   bool ktra = true;
		   for (int j = 0; j < m; j++) {
               if (data[i][j] == 0) {
				   ktra = false;
				   break;
			   }
		   }
		   if (ktra) dem ++;
	   }
	   if (maxxl < dem ) {
		   maxxl = dem;
	   }
	}

	for (int i = 0; i < 2; i++) {
		if (i) {
			for (int j = 0; j < n; j++) {
				if (data[j][kk] == 0) {
                    data[j][kk] = 1;
				}
				else {
					data[j][kk] = 0;
				}
			}
			backtrack(kk+1, doi + 1);
			for (int j = 0; j < n; j++) {
				if (data[j][kk] == 0) {
                    data[j][kk] = 1;
				}
				else {
					data[j][kk] = 0;
				}
			}

		}
		else backtrack(kk+1, doi);
	}
}

int main() {
	//freopen("input.txt", "r", stdin);
	int sl;
	cin >> sl;
	for (int stt = 1; stt <= sl; stt++) {
	    cin >> n >> m >> k;
		maxxl = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				data[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				cin >> data[i][j];
			}
		}

		if (k > n) {
			int kn = k - n;
			if (kn % 2 == 0) {
				k = n;
			}
			else {
				k = n - 1;
			}
		}
		backtrack(0,0);
		cout << "Case #"<<stt<<" ";
		cout << maxxl<<endl;
	}


	return 0;
}