【dfs】 2397. 被列覆盖的最多行数

https://leetcode.cn/problems/maximum-rows-covered-by-columns/description/?envType=daily-question&envId=2024-01-04

class Solution {
public:
    // 将Mat 第cur 列设为0
    void processMat(vector<vector<int>> &mat, int cur) {
        for (int i = 0; i < mat.size(); i++) {
            mat[i][cur] = 0;
        }
    }
    // 得到最大的全零行数
    int getMaxRows(vector<vector<int>>& mat) {
        int res = 0;
        for (auto row : mat) {
            int flag = 0;
            for(auto ele : row) {
                flag |= ele;
                if (flag) break;
            }
            if (flag == 0) res++;
        }
        return res;
    }
    int res = 0;
    void dfs(vector<vector<int>> mat, int cur, int coveredRows, int numSelect) {
        // if () return;
        // cout << "cur: " << cur << "coveredRows: "<< coveredRows <<"numSelect:" << numSelect << endl;
        if (cur == mat[0].size() || numSelect <= 0 ||  mat[0].size() - cur < numSelect) {
            res = max(res, coveredRows);
            return;
        };
        vector<vector<int>> tmp = mat;
        // 选了第cur 列
        processMat(tmp, cur);
        dfs(tmp, cur + 1, getMaxRows(tmp), numSelect - 1);
        // 不选第cur 列
        dfs(mat, cur + 1, coveredRows, numSelect);
    }
    int maximumRows(vector<vector<int>>& matrix, int numSelect) {
        dfs(matrix, 0, 0, numSelect);
        return res;
    }
};