// C# program to Check if we
// can make the given matrix
// increasing matrix or not
using System;
class GFG
{
static readonly int n = 4;
static readonly int m = 4;
// Function to find increasing matrix
static void findIncreasingMatrix(int [,]dp)
{
bool flag = false;
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
// Putting max into b as per
// the above approach
int b = Math.Max(dp[i - 1, j],
dp[i, j - 1]);
// If b is -1 than putting 1 to it
b = Math.Max(1, b);
// If dp[i,j] has to be
// filled with max
if (dp[i, j] == -1)
dp[i, j] = b;
// If dp[i,j] is less than from
// it's left element or from
// it's upper element
else if (dp[i, j] < b)
flag = true;
}
}
// If it is not possible
if (flag == true)
Console.WriteLine("-1");
else
{
// Printing the increasing matrix
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
Console.Write(dp[i, j] + " ");
}
Console.WriteLine();
}
}
}
// Driver code
public static void Main()
{
/* Here the matrix is 1 2 3 3
1 -1 7 -1
6 -1 -1 -1
-1 -1 -1 -1
Putting 0 in first row & column */
int [,]dp = {{ 0, 0, 0, 0, 0 },
{ 0, 1, 2, 2, 3 },
{ 0, 1, -1, 7, -1 },
{ 0, 6, -1, -1, -1 },
{ 0, -1, -1, -1, -1 }};
findIncreasingMatrix(dp);
}
}
/* This code contributed by PrinciRaj1992 */