Finished implementation of R_m_n computation through backtracking