Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/chapter19dynamicprogramming/Rod_Cutting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.*;
public class cut{
public static int Rod_Cutting(int p[],int n)
{
int max=Integer.MIN_VALUE;
if(n==0)
return 0;
else
{
for(int j=0;j<n;j++)

{
max=Math.max(max,
p[j]+cut_rod(p,n-j-1));
}
}
return max;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the prices of the rod ");
int arr[]=new int[8];
for(int i=0;i<8;i++)
{
arr[i]=sc.nextInt();
}
int n=sc.nextInt();
int p=cut_rod(arr,n);
System.out.println("Maximum value is "+p);
}
}