Fill the dp table
for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { for ( int k = 0 ; k <= n ; k ++ ) { dp [ i , j , k ] = dp [ i - 1 , j , k ] ; if ( k != 0 ) { dp [ i , j , k ] += k * dp [ i - 1 , j ^ arr [ i - 1 ] , k - 1 ] ; } } } }