Driven code
static void Main ( ) { int [ ] arr = new int [ ] { 1 , 3 , 1 , 5 , 2 } ; int n = arr . Length ; int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) dp [ i , j ] = 0 ; Console . Write ( solve ( dp , arr , 0 , n - 1 , 1 ) ) ; } }