题目 <https://leetcode-cn.com/problems/h-index/>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
int maximalRectangle(char** matrix, int matrixSize, int* matrixColSize){
if(matrixSize == 0 || matrixColSize[0] == 0){
return 0;
}
int **dp;
dp = malloc(sizeof(int *) * matrixSize);//dp[i][j]表示matrix[i][j]为结尾的行长度
int i,j,k;
for(i=0;i<matrixSize;i++){
dp[i] = malloc(sizeof(int) * matrixColSize[i]);
}
int x,y;
int area = 0,area1;
for(i=0;i<matrixSize;i++){
for(j=0;j<matrixColSize[i];j++){
if(matrix[i][j] == '0'){
dp[i][j] = 0;
continue;
}
if(i-1>=0){
dp[i][j] = dp[i-1][j]+1;
}else{
dp[i][j] = 1;
}
x=dp[i][j];
y=0;
for(k=j;k>=0&&matrix[i][k]=='1';k--){
x = min(x,dp[i][k]);
y++;
area1 = x*y;
area = max(area,area1);
}
}
}
for(i=0;i<matrixSize;i++){
free(dp[i]);
}
free(dp);
return area;
}