diff --git a/src/main/python/algorithms/other/rodcutting.py b/src/main/python/algorithms/other/rodcutting.py new file mode 100644 index 0000000..8df1390 --- /dev/null +++ b/src/main/python/algorithms/other/rodcutting.py @@ -0,0 +1,18 @@ +#RodCutting Problem +# This program solves the rod cutting problem using a dynamic programming approach in python + +INT_MIN = -32767 + +def RodCutting(price): + n=len(price) + val = [0 for x in range(n+1)] + val[0]=0 + for i in range(1, n + 1): + mx = INT_MIN + for j in range(i): + mx=max(mx, price[j] + val[i-j-1]) + val[i] = mx + return val[n] + +arr = list(map(int,input().split())) +print(str(RodCutting(arr)))