intmaximalRectangle(vector<vector<char>>& matrix){ int row = matrix.size(); if (!row)return0; int col = matrix[0].size(); if (!col)return0; vector<vector<int>> count; for (int i = 0; i < row; i++) count.push_back({ (matrix[i][0] - '0') }); for (int i = 0; i < row; i++) { for (int j = 1; j < col; j++) { if (matrix[i][j - 1] == '0') count[i].push_back(matrix[i][j] - '0'); else count[i].push_back(count[i][j - 1] + matrix[i][j] - '0'); } }
int res = count[0][0]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (matrix[i][j] == '1') { int width = count[i][j]; for (int k = i; k >= 0; k--) { if (matrix[k][j] == '0')break; width = count[k][j] < width ? count[k][j] : width; int area = width * (i - k + 1); res = area > res ? area : res; } } } } return res; }
//The end criterion is the case of a one-dimensional vector: template <typename T> classDotProduce<1, T>{ public: static T result(T* a, T* b){ return *a * *b; } };