Recursion and backtracking

why wrong ans in some test cases
my code https://ide.codingblocks.com/s/149176