#K32967. Longest Increasing Path in a Matrix

    ID: 24983 Type: Default 1000ms 256MiB

Longest Increasing Path in a Matrix

Longest Increasing Path in a Matrix

Given a matrix of integers, find the length of the longest strictly increasing path. From any cell, you can move in four directions (up, down, left, right), but only to a cell with a higher value. Use depth-first search (DFS) with memoization to achieve optimal performance.

For example, for the matrix:

9 9 4
6 6 8
2 1 1

the longest increasing path has length 4.

inputFormat

The first line contains two integers N and M representing the number of rows and columns respectively. This is followed by N lines where each line contains M integers separated by spaces, representing the elements of the matrix.

outputFormat

Output a single integer representing the length of the longest strictly increasing path in the matrix.

## sample
3 3
9 9 4
6 6 8
2 1 1
4