Stores the dp states where dp [ i ] [ j ] represents count of arrays of length i + 1 having their last element as j
int [ ] [ ] dp = new int [ N ] [ M + 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M + 2 ; j ++ ) { dp [ i ] [ j ] = 0 ; } }