Rope Cutting Problem | thiscodeWorks

PHOTO EMBED

Wed Sep 14 2022 01:54:55 GMT+0000 (Coordinated Universal Time)

Saved by @anujnema #java

import java.io.*;
import java.util.*;
 
class GFG 
{
	static int maxCuts(int n, int a, int b, int c)
	{
		if(n == 0) return 0;
		if(n < 0)  return -1;
 
		int res = Math.max(maxCuts(n-a, a, b, c), 
		          Math.max(maxCuts(n-b, a, b, c), 
		          maxCuts(n-c, a, b, c)));
 
		if(res == -1)
			return -1;
 
		return res + 1; 
	}
  
    public static void main(String [] args) 
    {
    	int n = 5, a = 2, b = 1, c = 5;
    	
    	System.out.println(maxCuts(n, a, b, c));
    }
}
content_copyCOPY

Rope Cutting Problem from G4G Course

https://www.thiscodeworks.com/rope-cutting-problem-java-gfg-geeksforgeeks-lecture-recursion-rope-cutting/62003e644dd44f0015f3cccd