Блог пользователя Parvej

Автор Parvej, история, 4 года назад, По-английски

Hello. I googled the following problem but didn't find any related article.

problem: You are given a N*M size grid of integers. Initially, you are at the leftmost top cell (1,1). You can either go right or down. There are (N+M-2) C N-1 paths in the grid. What is the Longest Increasing Subsequence's length of all the paths.

let A,
{1 2 4 3 }
{2 1 3 4 }
{1 2 4 5 }

You can go take A[1][1],A[1][2],A[2][3],A[2][4],A[3][4] from the path (1,1) -> (1,2) -> (2,2) -> (2,3) -> (2,4) -> (3,4) .

so the answer is 5.

1<=N,M<=1e3

A[i][j]<=1e9;

NB: Can we print the path under the given constraints?

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
4 года назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Add the values in the grid in ascending order.

Lets say you are adding the value $$$x$$$ at position $$$(i,j)$$$ then $$$\text{lis}[i][j]=max(\text{lis}[i'][j']+1)$$$ where $$$i' \leq i$$$ and $$$j'\leq j$$$. These max queries can be done using a 2D Segment Tree.