Sudo Placement [ 1.5 ] | Wolfish | C # program for SP - Wolfish ; Function to find the maxCost of path from ( n - 1 , n - 1 ) to ( 0 , 0 ) | recursive approach ; base condition ; reaches the point ; i + j ; check if it is a power of 2 , then only move diagonally ; if not a power of 2 then move side - wise ; Function to return the maximum cost ; calling dp function to get the answer ; Driver Code ; Function calling to get the answer
using System ; class GFG { static int size = 1000 ; public static int maxCost ( int [ , ] a , int m , int n ) { if ( n < 0 m < 0 ) return - 1 ; else if ( m == 0 && n == 0 ) return 0 ; else { int num = m + n ; if ( ( num & ( num - 1 ) ) == 0 ) return a [ m , n ] + maxCost ( a , m - 1 , n - 1 ) ; else return a [ m , n ] + Math . Max ( maxCost ( a , m - 1 , n ) , maxCost ( a , m , n - 1 ) ) ; } } public static int answer ( int [ , ] a , int n ) { return maxCost ( a , n - 1 , n - 1 ) ; } static void Main ( ) { int [ , ] a = new int [ , ] { { 1 , 2 , 3 , 1 } , { 4 , 5 , 6 , 1 } , { 7 , 8 , 9 , 1 } , { 1 , 1 , 1 , 1 } } ; int n = 4 ; Console . Write ( answer ( a , n ) ) ; } }