realize recursive backtracking algorithm