Neighbouring Enemy problem

Why getting wrong answer even code is correct???

Suppose that dp[i] stores the frequency if each element in the array.
Then the answer upto index i should be: dp[i]=max(dp[i-1],dp[i-2]+dp[i]*i)