int maximalRectangle(vector<vector<char> > &matrix) { int row = matrix.size(); if(row == 0){ return 0; } int col = matrix[0].size(); if(col == 0){ return 0; } vector<vector<int> > h(row, vector<int>(col)); for(int j = 0; j < col; j++){ if(matrix[0][j] == '1'){ h[0][j] = 1; } } for(int i = 1; i < row; i++){ for(int j = 0; j < col; j++){ if(matrix[i][j] == '1'){ h[i][j] = h[i - 1][j] + 1; }else{ h[i][j] = 0; } } } int maxarea = 0; for(int i = 0; i < row; i++){ int area = largestRect(h[i]); if(area > maxarea){ maxarea = area; } } return maxarea; }
int main() { int n; while (scanf("%d",&n) && n) { for (int i=1; i<=n; ++i) { scanf("%d", height+i); } N = n; #ifdef ONLINE_JUDGE printf("%I64u\n", largestRect()); #else printf("%llu\n", largestRect()); #endif } return 0; }
TEST(HDOJ1506DP, case1){ N=3; height[1]=2; height[2]=1; height[3]=2; uint64_t m = largestRect(); LONGS_EQUAL(3, m); }
TEST(HDOJ1506DP, case3){ N=6; height[1]=2; height[2]=5; height[3]=2; height[4]=5; height[5]=5; height[6]=2; uint64_t m = largestRect(); LONGS_EQUAL(12, m); }
TEST(HDOJ1506DP, case2){ N=7; height[1]=2; height[2]=1; height[3]=4; height[4]=5; height[5]=1; height[6]=3; height[7]=3; uint64_t m = largestRect(); LONGS_EQUAL(8, m); }