I know this has 5 problems, but they are ALL related. I also set the point value at the max 1500 (300 pts. per problem). The should be super easy for an expert.

Given a rod of length n inches and an array of prices that contains prices of all pieces of size smaller than n. Determine the maximum value obtainable by cutting up the rod and selling the pieces. For example, if length of the rod is 8 and the values of different pieces are given as following, then the maximum obtainable value is 22 (by cutting in two pieces of lengths 2 and 6)
length | 1 2 3 4 5 6 7 8 -------------------------------------------- price | 1 5 8 9 10 17 17 20
And if the prices are as following, then the maximum obtainable value is 24 (by cutting in eight pieces of length 1)
length | 1 2 3 4 5 6 7 8 -------------------------------------------- price | 3 5 8 9 10 17 17 20
The naive solution for this problem is to generate all configurations of different pieces and find the highest priced configuration. This solution is exponential in term of time complexity. Let us see how this problem possesses both important properties of a Dynamic Programming (DP) Problem and can efficiently solved using Dynamic Programming.
1) Optimal Substructure:
We can get the best price by making a cut at different positions
and comparing the values obtained after a cut. We can recursively
call the same function for a piece obtained after a cut.
Let cutRoad(n) be the required (best possible price) value for a rod of lenght n. cutRod(n) can be written as following.
cutRod(n) = max(price[i] + cutRod(n-i-1)) for all i in {0, 1 .. n-1}
2) Overlapping Subproblems
Following is simple recursive implementation of the Rod Cutting
problem. The implementation simply follows the recursive structure
mentioned above.
|
// A Naive recursive solution for Rod cutting problem #include<stdio.h> #include<limits.h> // A utility function to get the maximum of two integers int max(int a, int b) { return (a > b)? a : b;} /* Returns the best obtainable price for a rod of length n and price[] as prices of different pieces */ int cutRod(int price[], int n) { if (n <= 0) return 0; int max_val = INT_MIN; // Recursively cut the rod in different pieces and compare different // configurations for (int i = 0; i<n; i++) max_val = max(max_val, price[i] + cutRod(price, n-i-1)); return max_val; } /* Driver program to test above functions */ int main() { int arr[] = {1, 5, 8, 9, 10, 17, 17, 20}; int size = sizeof(arr)/sizeof(arr[0]); printf("Maximum Obtainable Value is %d\n", cutRod(arr, size)); getchar(); return 0; } |
Output:
Maximum Obtainable Value is 22
Considering the above implementation, following is recursion tree for a Rod of length 4.
cR() ---> cutRod()
cR(4)
/ / \ \
/ / \ \
cR(3) cR(2) cR(1) cR(0)
/ | \ / \ |
/ | \ / \ |
cR(2) cR(1) cR(0) cR(1) cR(0) cR(0)
/ \ | |
/ \ | |
cR(1) cR(0) cR(0) cR(0)
In the above partial recursion tree, cR(2) is being solved twice. We can see that there are many subproblems which are solved again and again. Since same suproblems are called again, this problem has Overlapping Subprolems property. So the Rod Cutting problem has both properties (see this and this) of a dynamic programming problem. Like other typical Dynamic Programming(DP) problems, recomputations of same subproblems can be avoided by constructing a temporary array val[] in bottom up manner.
|
// A Dynamic Programming solution for Rod cutting problem #include<stdio.h> #include<limits.h> // A utility function to get the maximum of two integers int max(int a, int b) { return (a > b)? a : b;} /* Returns the best obtainable price for a rod of length n and price[] as prices of different pieces */ int cutRod(int price[], int n) { int val[n+1]; val[0] = 0; int i, j; // Build the table val[] in bottom up manner and return the last entry // from the table for (i = 1; i<=n; i++) { int max_val = INT_MIN; for (j = 0; j < i; j++) max_val = max(max_val, price[j] + val[i-j-1]); val[i] = max_val; } return val[n]; } /* Driver program to test above functions */ int main() { int arr[] = {1, 5, 8, 9, 10, 17, 17, 20}; int size = sizeof(arr)/sizeof(arr[0]); printf("Maximum Obtainable Value is %d\n", cutRod(arr, size)); getchar(); return 0; } |
Output:
Maximum Obtainable Value is 22
Time Complexity of the above implementation is O(n^2) which is much better than the worst case time complexity of Naive Recursive implementation.
I know this has 5 problems, but they are ALL related. I also set the point...
Please show all work. For this question. Also I would like to
know if this is considered an easy problem.
3. A boy start at restnd idrs doafrictiones slide. The bottom of the track s a hright & sbove the ground The byleaves the track horizontally, striking the ground at a distance d from the end of the slide. (4) (8 pointa) Draw a diagram for the problem, indicating the trajectory of the boy after he leaves the slide. (12...
Please show all work. For this question. Also I would like to
know if this is considered an easy problem.
2. A 10 kg block is released from a point A in the figure below. The track is frie- tionless except for the portion between points B and C, which has a length of d m. The block travels down the track, hits a spring of force constant 2250 and compresses the spring 0.3 m from its equilibrium position before...
In F=ma when summing the forces, I know they must all be in the same direction (along with the acceleration), but should they all be acting on a single point also (or acting relative to a point)? So if you had two forces acting on an object and say one is acting on the center and one is acting on some distance from the end, you must set up an origin point, and have two position vectors from the origin...
Please show all work. For this question. Also I would
like to know if this is considered an easy problem.
4 A bulle of mass M. The in the figure below. mass m and speed v strikes and becomes embedded in a pendulum bob pendulum bob is suspended by a massless cord of length l as shown (a) (s points) Is energy conserved during this collision? Is energy conserved efter the collision? (b) (s points) Find the speed of the...
help!! I know this is
technically two problems but I ran out of question so please help
if you can. I don't have anymore questions left!
also posting problem 1 as an reference but just help to the top
2
As in Problem 1, once again, you are borrowing $6500 to purchase a car. However, now the first payment is due immediately. There will be a total of 36 monthly payments (The first payment occurs immediately. The remaining 35 occur...
I want to know if these statements are true/false, and also the reasons if they are false. 6. All computer programs written in modern languages can be implemented by some Turing machines. 7. It is possible to automatically translating programs written in C into an equivalent Turing machine. 8. The number of undecidable problems is countably infinite. 9. There is a problem solvable by Turing machines with two tapes but unsolvable by Turing machines with a single tape. 10. Every...
I need to know all the steps to get parts a+b. thank you.
(13%) Problem 5: m's. A rock takes 2.65 s to ht the ground when it is thrown straight up from the cliff with an initial velocity of 7 IS 15 50% Part (a) Calculate the height of the cliff in m. pleted-14.005 pleted h=14.01 V Correct! leted pleted | tial | 50% Part (b) How long would it take to reach the ground if it is thrown...
Hey guys, I am struggling with this problem. I dont know where
to begin with. I have to make a model in excel for this problem and
solve from A to D. Can someone help me solving this problem by
showing each step please ? I would really apprecite it. PS: please
make to put a clear picture and a good explanation about the answer
you come up with.
Problem 4 (6 points Baseball umpiring crews are currently in four...
I need help with these practice test problems. I also need to
see work cause I don’t know where to start
initial speed of 24.0 3. [14 pts] A daredevil is shot out of a cannon at 40.0° to the horizontal with an m/s. The daredevil travels past the highest point and then falls towards the ground in a parabolic path A net is positioned height of 10.0 m above the ground. How long is the daredevil in the air?...
Hi all the answers are given on this worksheet I just need to
know how to do part (e) and calculate the two numbers in my TI-84.
(I use my TI-84 to get z and p-value)
Problem 4: Two Proportions In 1995, the American Cancer Society randomly sampled 1500 adults of which 555 smoked. In 2005, they surveyed 1730 adults and ound that 578 of them smoked. At the 5% level of significance test the claim that the proportion of...