Largest rectangular sub matrix with the number difference k

北城余情 提交于 2020-01-25 19:00:26

问题


Input: A 2-dimensional array NxN - Matrix - with numbers from 0 to 9.

Output: Largest rectangular area where absolute value of number's difference in area is k.

Possible input:

int k=3;
const int N=5;
int matrix[N][N] = {{9, 3, 8, 2, 0},
                    {2, 7, 6, 8, 5},
                    {8, 5, 7, 7, 6},
                    {3, 0, 4, 0, 9},
                    {7, 2, 0, 4, 0}};

Is it related to find largest area in histogram problem? If it does how I can transform this matrix two binary matrix? And how to approach this kind of problems?

Answer: largest area is 8 by following sub matrix {{7, 6, 8, 6}, {5, 7, 7, 6}}

What I think should be done:

  1. Transform matrix to binary matrix
  2. Create histogram from binary matrix
  3. Calculate largest area using largest area in histogram.

What is unclear is how to transform input matrix to binary matrix.

来源:https://stackoverflow.com/questions/25965492/largest-rectangular-sub-matrix-with-the-number-difference-k

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!