Solution is pretty straightforward based on parity and bit position, but to avoid all those position reflections in your head during coding, generate codes for say N=5 and look at value of "k XOR x"
I found the problem . I do this using DP,dp[i][0] dp[i][j] represent the ways to put '0' and '1' and the answer to too big for long long . So for this problem (only ask for ok or not ok)just set a max range ,when dp[i][j]>max just let dp[i][j]=max. Hope help.