Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new problem #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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;
}