Java Simple DP Solution with state table
DP State\n\n1 0 1 0 0      1 0 1 0 0\n1 0 1 1 1  =>  2 0 2 1 1\n1 1 1 1 1  =>  3 1 3 2 2\n1 0 0 1 0      4 0 0 3 0\n\nFind the max area row by row, as we can se
DP State\n```\n1 0 1 0 0      1 0 1 0 0\n1 0 1 1 1  =>  2 0 2 1 1\n1 1 1 1 1  =>  3 1 3 2 2\n1 0 0 1 0      4 0 0 3 0\n```\nFind the **max area** row by row, as we can see `3 1 3 2 2` contains the **max area**.\n\n```java\nclass Solution {\n  public int maximalRectangle(char[][] matrix) {\n    if (matrix.length <= 0) return 0;\n    int n = matrix.length;\n    int m = matrix[0].length;\n    int[][] dp = new int[n][m];\n    int maxArea = 0;\n    for (int i = 0; i < n; i++) {\n      for (int j = 0; j < m; j++) {\n        if (i == 0)\n\t\t  dp[i][j] = matrix[i][j] == \'1\' ? 1 : 0;\n        else\n\t\t  dp[i][j] = matrix[i][j] == \'1\' ? (dp[i-1][j] + 1) : 0;\n        int min = dp[i][j];\n        for (int k = j; k >= 0; k--) {\n          if (min == 0) break;\n          if (dp[i][k] < min) min = dp[i][k];\n          maxArea = Math.max(maxArea, min * (j - k + 1));\n        }\n      }\n    }\n    return maxArea;\n  }\n}\n```
['Dynamic Programming', 'Java']