From 152b04a57c3a7c18e24147912c0e869a63059fe2 Mon Sep 17 00:00:00 2001 From: Pavan-249 <64021665+Pavan-249@users.noreply.github.com> Date: Sat, 21 Aug 2021 18:10:24 +0530 Subject: [PATCH] Added new problem --- .../013_Rope Cutting Problem/main.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 001_RECURSION/013_Rope Cutting Problem/main.cpp diff --git a/001_RECURSION/013_Rope Cutting Problem/main.cpp b/001_RECURSION/013_Rope Cutting Problem/main.cpp new file mode 100644 index 0000000..76a8af8 --- /dev/null +++ b/001_RECURSION/013_Rope Cutting Problem/main.cpp @@ -0,0 +1,33 @@ +// Description: +/*You are given N ropes. A cut operation is performed on ropes such that all of them are reduced by the +length of the smallest rope.Display the number of ropes left after every cut operation until the +length of each rope is zero. +*/ +#include +using namespace std; + + +int maxCuts(int n, int a, int b, int c) +{ + if(n == 0) + return 0; + if(n <= -1) + return -1; + + int res = max(maxCuts(n-a, a, b, c), + max(maxCuts(n-b, a, b, c), + maxCuts(n-c, a, b, c))); + + if(res == -1) + return -1; + + return res + 1; +} +int main() { + + int n = 5, a = 2, b = 1, c = 5; + + cout<