I got the task where I must find the H shaped region which has the biggest sum of numbers in it. The 'H' shaped region is something like this:
x x
xxx
x x
The matrix's size must be 3*3 or bigger than that, and I don't have to work with rotated 'H' shape. However, it can move upwards and downwards if the matrix is that big (for example a 4*6 matrix).
I thought of first counting a "maximum" value, starting from the [0][0] element. However, I can't figure out how to move this region-counting along. Could you help me out, please?
#include<iostream>
int main(){
int n = 3;
int m = 4;
int mtx[n][m] = {
1,1,1,3,
1,1,1,3,
1,1,1,3
};
//counting the maximum H value
int min = 0;
for(int i = 0; i < n; i++){
max += mtx[i][0];
}
for(int i = 0; i < n; i++){
max += mtx[i][2];
}
min += mtx[1][1];
int counter = 0;
int j = 0;
int k = 0;
//finding if there is bigger
while(counter > max){
if(counter < max){
min = counter;
}
}
return 0;
}
Is it always 3x3? Is it always square? Are the vertical and horizontal bars always one element thick?
If not, what if the vertical sides of the H are, say, an even length - say 4? What is the position and what is the thickness of the horizontal bar in that case?
If you have an accessible specification of this problem please post it as original - NOT your rewording of it.