countB is count of ways with a building at the end countS is count of ways with a space at the end prev_countB and prev_countS are previous values of countB and countS respectively . Initialize countB and countS for one side
int countB = 1 , countS = 1 , prev_countB , prev_countS ;