The Magical Sequence
A Magical Sequence is defined as shown.
Magical[1] = 0
Magical[2] = 1
Magical[n] = 1*Magical[n-1] + 2*Magical[n-2] + 3*1, for n > 2
Given n (1 <= n <= 10 )
, find Magical[n]
.
Example 1: input1: 3 Output: 4 Explanation:
Magical[n] = 1*Magical[n-1] + 2*Magical[n-2] + 3*1
Magical[3] = 1*Magical[2] + 2*Magical[1] + 3*1
Magical[3] = 1*1 + 2*0 + 3*1
Magical[3] = 4
Aucun commentaire:
Enregistrer un commentaire