Entringer Number | JAVA Code For Entringer Number ; Return Entringer Number E ( n , k ) ; Base cases ; Finding dp [ i ] [ j ] ; Driver program to test above function
import java . util . * ; class GFG { static int zigzag ( int n , int k ) { int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= Math . min ( i , k ) ; j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ; } return dp [ n ] [ k ] ; } public static void main ( String [ ] args ) { int n = 4 , k = 3 ; System . out . println ( zigzag ( n , k ) ) ; } }