SUMSUMS - Not able to figure out the recurrence

Not able to figure out the recurrence for the question. At every step there are are n possible states (representing each cow). how to handle it ?