If x >= N or y >= M
if ( x == a . Length && y == b . Length ) return 0 ; int curr = 0 ; if ( dp . ContainsKey ( new Tuple < int , int > ( x , y ) ) ) { curr = dp [ new Tuple < int , int > ( x , y ) ] ; }