SarthakKeshari / CPP-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
46 stars 132 forks source link

Cutting a Rod #454

Closed PrakharRathore123 closed 2 years ago

PrakharRathore123 commented 2 years ago

Choose your form and fill it -

1. Form 1(C++ Solution contributors)

Form 1

2. Form 2(C++ Documentation Contributors)


1) Form 1

Issue Id you have worked upon -

399

Briefly explain your program logic -

1) Write a Function to find the maximum of two integers 2) Write a Function to find the maximum profit 3)Let an array of size n+1 to store different profit possible 4)Initialize the first element of let array be 0 5)Find the max profit possible by checking all the possible cases 6)Store all the profit in ascending order in array 7)return the last element of array

Screenshots(Attach 2 screenshots of your own input and output) -

Attach here

ROD1 ROD2


Test cases-

Test caes1- if the length of the rod is 8 and the values of different pieces {1 5 8 9 10 17 17 20} then the maximum obtainable value is 22. by cutting in two pieces of lengths 2 and 6 Test caes2- if the length of the rod is 5 and the values of different pieces {5 8 7 9 6} then the maximum obtainable value is 25. by cutting in 5 pieces of lengths 1 each

Checklist:

Eg - If your code follow the below guidelines. Kindly change [] to [x]

All the conditions should be fulfilled for considering your code for merging -


2) Form 2

Issue Id you have worked upon -

Kindly write your answer here


Checklist:

Eg - If your code follow the below guidelines. Kindly change [] to [x]

All the conditions should be fulfilled for considering your Pull Request for merging -

PrakharRathore123 commented 2 years ago

@SarthakKeshari Kindly acknowledge this.