Hey, I am using the bottom-up DP approach to solve the rod cutting problem and my code passed all the test cases except one, I am not able to find the mistake.
Here is my code ----
int main()
{
long long n ;
cin>>n ;
long long cost[n] ;
for(int i=0 ; i<n ; i++)
{
cin>>cost[i] ;
}
long long dp[n+1];
dp[0] = 0 ;
dp[1] = cost[0] ;
for(int i= 2 ; i<=n ; i++)
{
dp[i] = max(cost[i-1] , dp[i-1]+dp[1]);
}
cout<<dp[n] ;
return 0 ;
}