Untitled

 avatar
unknown
plain_text
a year ago
1.7 kB
4
Indexable
#include <iostream>
#include <fstream> // Thư viện cho việc đọc file

using namespace std;

const int MAX_N = 1000; // Số hàng tối đa
const int MAX_M = 1000; // Số cột tối đa
int n, m, k, ans;
int arr[MAX_N][MAX_M]; // Mảng 2 chiều

int find(int x) {
    int count = 0;
    for (int i = 0; i < m; i++) {
        if (arr[x][i] == 0) {
            count++;
        }
    }
    if (k >= count && (k - count) % 2 == 0) {
        ans = 1;
        for (int i = 0; i < n; i++) {
            bool check = true;
            if (i != x) {
                for (int j = 0; j < m; j++) {
                    if (arr[x][j] != arr[i][j]) {
                        check = false;
                    }
                }
                if (check) {
                    ans++;
                }
            }
        }
    }
    return ans;
}

int main() {
    ifstream file("src/DaoCot/input.txt"); // Mở file đầu vào
    int T;
    file >> T; // Đọc số lượng test case

    for (int tc = 1; tc <= T; tc++) {
        file >> n >> m >> k; // Đọc các giá trị n, m, k cho mỗi test case

        // Đọc dữ liệu vào mảng arr
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                file >> arr[i][j];
            }
        }

        ans = 0;
        // Duyệt qua từng hàng và tìm số lượng cột có giá trị 0
        for (int i = 0; i < n; i++) {
            int num = find(i);
            if (ans < num) {
                ans = num;
            }
        }
        cout << "Case #" << tc << " " << ans << endl; // In kết quả cho mỗi test case
    }

    file.close(); // Đóng file
    return 0;
}
Editor is loading...
Leave a Comment