Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int** createMatrix(int rows)
- {
- int** mtx = new int* [rows];
- for (int i = 0; i < rows; i++)
- {
- int colls;
- cin >> colls;
- mtx[i] = new int[colls + 1] {0};
- mtx[i][0] = colls;
- for (int j = 1; j < colls + 1; j++)
- {
- cin >> mtx[i][j];
- }
- }
- return mtx;
- }
- void deleteMatrix(int** matrix, int rows)
- {
- for (int i = 0; i < rows; i++)
- {
- delete[] matrix[i];
- }
- delete[] matrix;
- }
- void printMatrix(int** matrix, int rows)
- {
- for (int i = 0; i < rows; i++)
- {
- int sizeOfRow = matrix[i][0];
- for (int j = 1; j < sizeOfRow + 1; j++)
- {
- cout << matrix[i][j] << " ";
- }
- cout << endl;
- }
- }
- int indi = 0, indj = 0, indiCopy, indjCopy;
- int findWay(int** matrix, int rows, int x, int y)
- {
- int way=1,maxLen=1;
- for (int i = x - 1; i <= x + 1; i++)
- {
- if (i < 0 || i >= rows)
- {
- continue;
- }
- for (int j = y - 1; j <= y + 1; j++)
- {
- if (j <1 || j > matrix[i][0])
- {
- continue;
- }
- if (matrix[i][j] > matrix[x][y])
- {
- way=1+findWay(matrix,rows,i,j);
- if(way>maxLen)maxLen=way;
- }
- }
- }
- return maxLen;
- }
- unsigned int findLongestLine2(int** matrix, int rows)
- {
- int maxi=0;
- for (int i = 0; i < rows; i++)
- {
- int sizeOfRow = matrix[i][0];
- for (int j = 1; j < sizeOfRow + 1; j++)
- {
- int br=findWay(matrix,rows,i,j);
- if(br>maxi)maxi=br;
- }
- }
- return maxi;
- }
- int main()
- {
- int rows;
- cin >> rows;
- int length = 1, maxLength = 0;
- int** mtx = createMatrix(rows);
- cout << findLongestLine2(mtx, rows, length, maxLength);
- deleteMatrix(mtx, rows);
- /*
- 4
- 3 4 8 9
- 2 2 10
- 5 3 11 7 0 4
- 3 1 3 12
- output 7
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement