多维数组中的第一个最低密度数组

First Lowest Density Array In a multi-dimensional array

我试图找到多维数组中的最低密度。

假设一个数组看起来像这样

1 1 1
1 1      <- Lowest density is this one row:1 column:2.
1 1 1
1 1
1 1 1
1        <- Lowest density is this one row 2: column:1.

这是我的错误代码

Public ProcessedBits()() As Byte

'Lowest Density detector to find out which values have the highest priority.
Dim nextLowestDensityColumn As Integer = Integer.MaxValue
Dim nextLowestDensityRow As Integer = Integer.MaxValue

For Row = 0 To Uniques.Length - 1
    For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.
        If ProcessedBits(Row)(Column) = 1 Then  'if the column is processed, then skip it and process the next one.
            If Column < nextLowestDensityColumn AndAlso Row < nextLowestDensityRow Then
                nextLowestDensityColumn = Column + 1
                nextLowestDensityRow = Row
            End If
        End If
    Next
Next

If nextLowestDensityRow <> Integer.MaxValue AndAlso nextLowestDensityColumn <> Integer.MaxValue Then
    Row = nextLowestDensityRow
End If

半固定码

        'Lowest Density detector to find out which values have the highest priority.
        Dim nextLowestDensityColumn As Integer = Integer.MaxValue
        Dim nextLowestDensityRow As Integer = Integer.MaxValue

        For Row = 0 To Uniques.Length - 1
            For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.
                If ProcessedBits(Row)(Column) = 1 AndAlso Uniques(Row).Length <> Column + 1 AndAlso ProcessedBits(Row)(Column + 1) = 0 Then  'if the column is processed, then skip it and process the next one.
                    If (Column + 1) < nextLowestDensityColumn Then
                        nextLowestDensityColumn = Column + 1
                        nextLowestDensityRow = Row
                    End If
                End If
            Next
        Next

        If nextLowestDensityRow <> Integer.MaxValue AndAlso nextLowestDensityColumn <> Integer.MaxValue Then
            Row = nextLowestDensityRow
        End If

已修复

        'Lowest Density detector to find out which values have the highest priority.
        Dim nextLowestDensityColumn As Integer = Integer.MaxValue
        Dim nextLowestDensityRow As Integer = Integer.MaxValue

        For Row = 0 To Uniques.Length - 1
            For Column = 0 To Uniques(Row).Length - 1 'check each column in current row.
                If ProcessedBits(Row)(Column) = 1 AndAlso Uniques(Row).Length <> Column + 1 AndAlso ProcessedBits(Row)(Column + 1) = 0 Then  'if the column is processed, then skip it and process the next one.
                    If (Column + 1) < nextLowestDensityColumn Then
                        nextLowestDensityColumn = Column + 1
                        nextLowestDensityRow = Row
                    End If
                End If
            Next
        Next

        If nextLowestDensityRow <> Integer.MaxValue AndAlso nextLowestDensityColumn <> Integer.MaxValue Then
            Row = nextLowestDensityRow
        End If