[Solved] Explain the following doubts please


why is dp initialized to 0?

for using for example addition operation dp[i]+=dp[i-2<0?0:i-2]; you should use a valid value not a random value

why do we subtract ‘0’*10?

for conversion of char to int you substarct the ascii of ‘0’ (0x30) for example '1' /* 0x31 */ - '0' /* 0x30 */ = 1

and how does the part of dp[i-1] & dp[i-2] work? (dp[i]+=dp[i-2<0?0:i-2];)

this instruction is equivalent:

if (i-2<0)
    dp[i]+=dp[0];
else
    dp[i]+=dp[i-2];

2

solved Explain the following doubts please