COUNTREL Recursive relation

Please can anyone post how they came up with this recurrence formula.Thanks in Advance.COUNTREL - Editorial - editorial - CodeChef Discuss