小编Ash*_*ain的帖子

如何找到给定矩阵的最大排序子矩阵(按行排序和逐列排序)?

给定n*n阶的矩阵.我需要找到最大的排序子矩阵的长度(以in row-wisecolumn-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)

c++ python algorithm dynamic-programming

7
推荐指数
1
解决办法
461
查看次数

标签 统计

algorithm ×1

c++ ×1

dynamic-programming ×1

python ×1