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
33 changes: 33 additions & 0 deletions 001_RECURSION/013_Rope Cutting Problem/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>
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<<maxCuts(n, a, b, c);

return 0;
}