给定n*n阶的矩阵.我需要找到最大的排序子矩阵的长度(以in row-wise和column-wisein方式排序increasing order).由于我的逻辑中存在一些错误,我制作了以下代码,但没有给出正确的输出.
我的伪代码:
arr=[map(int,raw_input().split()) for j in range(n)] #given list
a=[[0 for j in range(n)]for i in range(n)] #empty list
a[0][0]=1
for i in range(n):
for j in range(1,n):
if i==0 and arr[i][j-1]<=arr[i][j]: #compare list element with the
right element
a[i][j-1]=a[i][j-1]+1
if i>0 and arr[i][j-1]>=arr[i-1][j-1]: #compare list element with the
top for i>0
a[i][j-1]=a[i-1][j-1]+1
if i>0 and arr[i][j-1]<=arr[i][j]: #compare the same element with the
right element for i>0
a[i][j-1]=a[i][j-1]+1
print maximum number present in …Run Code Online (Sandbox Code Playgroud)