how can i solve it by using backtracking?
How can i solve by backtracking?
you can easily make a recurrance relation to find the number of integers.
you have to make an n-digit number.
so for the ith digit, you have 2 options.
- You can place
aiat ith place. If you do this, you can place eitheraiorbiat i+1th place, it does not matter. So subproblem becomes for f(n-1) - You can place
biat the ith place, If you do this, you can place onlyaiat i+1th place, because you cant havebinext to next. So the subproblem becomes for f(n-2)
The recurrance relation becomes f(n) = f(n-1) + f(n-2)