advquoc2
quoc14
c_cpp
5 days ago
1.2 kB
6
Indexable
Never
#include <iostream> using namespace std; int N, M, K; int a[105][25]; int zero[105]; int visit[105]; bool check(int num_zero) { if (K < num_zero) return false; if (K == num_zero) return true; int tmp = K - num_zero; if (tmp % 2 == 0) return true; return false; } void solve(int testcase) { cin >> N >> M >> K; for (int i = 1; i <= N; i++) { zero[i] = 0; visit[i] = 0; } int ans = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) { cin >> a[i][j]; if (a[i][j] == 0) { zero[i]++; } } } for (int i = 1; i <= N; i++) { if (visit[i] == 0) { int dem_hang = 0; for (int row = 1; row <= N; row++) { for (int j = 1; j <= M; j++) { if (a[i][j] != a[row][j]) { break; } if (j == M) { dem_hang++; visit[i] = 1; visit[row] = 1; } } } if (check(zero[i]) == true) { if (dem_hang > ans) { ans = dem_hang; } } } } cout << "#" << testcase << " " << ans << endl; } int main() { freopen("Text.txt", "r", stdin); int t; cin >> t; for (int i = 1; i <= t; i++) { solve(i); } return 0; }
Leave a Comment