#include<bits/stdc++.h>
using namespace std;
int rodcut(int price[], int n)
{
if(n <= 0)
return 0;
int mx = INT_MIN, i;
for(i=0;i<n;i++)
{
mx = max(mx, price[i]+rodcut(price, n-i-1));
}
return mx;
}
int main()
{
int n, i;
cout << "Enter Rod Size :: ";
cin >> n;
int price[n];
cout << "\nEnter Each Road Price :: ";
for(i=0;i<n;i++)
{
cin >> price[i];
}
cout << "\nMaximum Benefit :: " << rodcut(price, n) << "\n";
return 0;
}
using namespace std;
int rodcut(int price[], int n)
{
if(n <= 0)
return 0;
int mx = INT_MIN, i;
for(i=0;i<n;i++)
{
mx = max(mx, price[i]+rodcut(price, n-i-1));
}
return mx;
}
int main()
{
int n, i;
cout << "Enter Rod Size :: ";
cin >> n;
int price[n];
cout << "\nEnter Each Road Price :: ";
for(i=0;i<n;i++)
{
cin >> price[i];
}
cout << "\nMaximum Benefit :: " << rodcut(price, n) << "\n";
return 0;
}
Comments
Post a Comment