I do think it interchanges diagonal and anti-diagonal comments.

if (j > 0 && i > 0) dp[i][j][1] += dp[i-1][j-1][1]; // anti-diagonal line (wrong. should diagonal line) if (i > 0) dp[i][j][2] += dp[i-1][j][2]; // vertical line if (j < m-1 && i > 0) dp[i][j][3] += dp[i-1][j+1][3]; // diagonal line (wrong. should anti-diagonal line)Longest Line of Consecutive One in Matrix