Rope cutting using recursion
// Online C++ compiler to run C++ program online
#include <iostream>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
int cutrope(int n, int a, int b, int c){
int count=0;
if(n==0){
return 0;
}
if (n<0){
return -1;
}
int res=max(cutrope(n-a,a,b,c),cutrope(n-b,a,b,c));
res =max(res,cutrope(n-c,a,b,c));
if (res==-1){
return -1;
}
else return res+1;
}
int main(){
cout<<cutrope(9,2,2,2);
}
Comments
Post a Comment