## Video of the week

This is a must-watch video about one of us trying to reach the stars :-)

Well done #HRejterzy

# Maximum sub-square in NxM matrix (Not all 0,1)

My task was to find sub-squre (simple square inside given matrix) in NxM matrix where sum of elements is max.

Output: max, x-index, y-index of first sub-square element and the solution is:

`#include <iostream>using namespace std; typedef struct{int value;int x;int y;} matrixElement; int main(){      int n = 3;int m = 4;matrixElement matrix[n][m];matrixElement matrixNew[n*m]; int z = 0;for(int i = 0; i<n; ++i){for(int k=0; k<m; ++k){// Put example values into the dwo-dim array (here I add indexes, You can do whatever).matrix[i][k].value = i + k;matrix[i][k].x = i;matrix[i][k].y = k;cout << matrix[i][k].value << " ";if(k == (m-1)){cout << "\n";} // Rewrite values into one-dim array.matrixNew[z].value = matrix[i][k].value;matrixNew[z].x = matrix[i][k].x;matrixNew[z].y = matrix[i][k].y;++z;}} /*cout << "\n";for(int zz = 0; zz<n*m; ++zz){cout << matrixNew[zz].value << " ";}cout << "\n";cout << "\n";*/ int max = -1;int xx = -1;int yy = -1;for(int ii=0; ii<(n*m)-m-1; ++ii){if(matrixNew[ii].y == (m-1))continue; // Use relations between values:// second element is +1 from the first one// third element of square is +m elements away from the first one// fourth is +m+1 from the first one                    if(matrixNew[ii].value + matrixNew[ii+1].value + matrixNew[ii+m].value + matrixNew[ii+m+1].value > max){max = matrixNew[ii].value + matrixNew[ii+1].value + matrixNew[ii+m].value + matrixNew[ii+m+1].value;xx = matrixNew[ii].x;yy = matrixNew[ii].y;}  } // Correct answer:cout << max << " " << xx << " " << yy << endl; cin.get();return 0;}`

1. It depends on You how to fill the matrix with values - I decided to add i, k indexes. You can do whatever, use random values or seconds or (..)

2. Every sub-square is created from four values in particular distance-configuration - first, first+1, first+m, first+1+m

3. You must remember that when You reach right boundary value - You skip creating sub-square because You cannot create one, for example from values: 3,4 (first row) and 1,2 (second row)

4. Count of steps related to creating sub-squares depends on particular condition, which is: for(int ii=0; ii<(n*m)-m-1; ++ii) - You cannot create sub-squares after You stop dealing with second-to-last row

5. You know how to find maximum value in one-dim array - so the rest is easy

The Key : change two-dim array into one-dim array (it is always better to deal with much simpler structure)

Your browser doesn't support this tag cloud Today I'd like to present how to combine share permissions and NTFS when granting network access to a particular resource for a particular user (or group). I've made a graphic that tells more than a...