Algorithm Design for Linear Programming
The approach you used is called dynamic programming.

In dynamic programming, a series of decisions are made in order to maximize some function, where the options available at any given time depend on the decision we have made before. You may want to check a tutorial on TopCoder or some course material at your hand.

You have started to figure out the recurrence relation, the hallmark of dynamic programming. However, it looks like you made an off-by-one error.

You can imitate the pseudocode in that tutorial. Or many other pseudocode such as those in the Introduction to algorithm by Corman et al.

Here is my pseudocode for this problem, where you can find the correct recurrence relation. I assume $n\ge4$; otherwise the only choice is to use 
company $A$ always.


Let $OPT$ be an array of size $n$.
$OPT[0]=0$, $OPT[1]=s_1r$, $OPT[2]=(s_1+s_2)r$, $OPT[3]=(s_1+s_2+s_3)r$
For $i$ = 4 to $n$,  $OPT[i] = \min(OPT[i-1] + s_ir, OPT[i-4] + 4c)$
Output $OPT[n]$