Initialize DP
for ( int i = 0 ; i < 18 ; i ++ ) { for ( int j = 0 ; j < 180 ; j ++ ) { for ( int k = 0 ; k < 180 ; k ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) { dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } } } return memo ( 0 , 0 , 0 , 1 ) ; }