How to solve a Dynamic Programming Problem ? | initialize to - 1 ; this function returns the number of arrangements to form ' n ' ; base case ; checking if already calculated ; storing the result and returning
int dp [ MAXN ] ; int solve ( int n ) { if ( n < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( dp [ n ] != -1 ) return dp [ n ] ; return dp [ n ] = solve ( n - 1 ) + solve ( n - 3 ) + solve ( n - 5 ) ; }