Stuck in a DP problem

Revision en1, by skpro19, 2017-08-27 16:04:18

The question is this.

The solution is something like this:

dp[1] = 1, dp[2] =3 ;

for(int i =3; i <= n ; i++) dp[i] = dp[i — 1] + dp[ i- 2] + 2;

How did one come with the formulation dp[i] = dp[ i — 1 ] + dp[i — 2] + 2 ?

Any help would be really appreciated.

Peace!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English skpro19 2017-08-27 16:04:18 376 Initial revision (published)