problem 31 inefficient algorithm

I'm frustrated with this one because we did backtracking in algorithms
and this is a popular backtracking problem but I'm just not remembering
how not count repititions