I did not understand what is going on in bottom up approach

i did not understand what is going on in bottom up approach

hi @Aditya-Kushwaha-914550392281281

it is a standard Dynamic Programming problem
	at dp[i][j] we are storing max profit from ith bottle to jth bottle
	first we consider case when we have only one bottle(i==j)
		if we have only one bottle then we are at last year so profit on each botte is arr[i]*n
	for other case suppose for we have bottle from i to j
	so we have 2 options either we sell ith bottle or jth bottle
	if we sell ith bottle our profit is arr[i]*year +d[i+1][j]
	and if we sell jth bottle our profit is arr[j]*year+dp[i][j-1]

complete explanation is in video
if you don;t understand it please see atleat 2-3 times
and also dry run the code it will help you a lot

int WineProblemBU(int *arr,int n){
	int dp[100][100]={};


	for(int x=0;x<n;x++){
	int i=0,j=x;
	while(i<n-x){
		int year=n-(j-i);
		if(i==j){
			dp[i][j]=year*arr[i];
		}
		else{
			dp[i][j]=max((dp[i][j-1]+arr[j]*year),(arr[i]*year+dp[i+1][j]));
		}
		i++;j++;
	}
}
// print maze for clarification
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(dp[i][j]==0)cout<<"00 ";
			else cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}

	return dp[0][n-1];
}