Understood the algorithm but not able to code

Sir, I am able to draw the tree for this problem and also know the probable algorithm. I am relating this problem with Count N Queens but I am not able to implement my algorithm in code. Also, the solution that I have submitted earlier was told to me by my one of the seniors, who solved the question by DP which has not been taught yet. I have unlocked the editorial but I am unable to understand that so please send the correct code for this problem.

@Syed-Siddiqui-2497215583854102,
What problem are you facing? The code in the editorial is correct. It is a DP question and approach. If the editorial is giving wrong answer just change int to long.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.