Initialize dp
for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < 90 ; j ++ ) { for ( int l = 0 ; l < 90 ; l ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { dp [ i ] [ j ] [ l ] [ k ] = - 1 ; } } } } return count ( 0 , 0 , 0 , 0 , num ) ; }