Develop a program that will read a value of k from the keyboard and then display C(k) and D(k). (D(k) is interesting because it turns out to be the number of ways that we can parenthesize an arithmetic expression that has k binary operators.)
Imagine a candy bar that has k places where it can be cut. You would like to know how many different sequences of cuts are possible to divide the bar into pieces. For example, if k is 3, you could cut the bar at location 1, then location 2, and finally at location 3. We indicate this sequence of cuts by 123. So if k is 3, we have six ways to divide the bar: 123, 132, 213, 231, 312, or 321. Notice that we have k possibilities for making the first cut. Once we make the first cut we have k - 1 places where a cut must be made. Recursively, this can be expressed as
C(k) = k C(k - 1)
Lets make this a bit more interesting by adding a restriction. You must always cut the leftmost pieces that can be cut. Now if k is 3, we can cut the bar at locations 123, 132, 213, 312, or 321. A cutting sequence of 231 would not be allowed, because after the cut at 2 we would have to make the cut at location 1, since it is the leftmost piece. We still have k possibilities for making the first cut, but now we have to count the number of ways to cut two pieces and multiply. Recursively, this can be expressed as
The recursive algorithm for C(k) is easy to implement and should be familiar. The recursive algorithm for D(k) is slightly more complicated, but can be based on C(k). Instead of making a single recursive call, loop and make the recursive calls. As with previous projects, this one can experience overflow if the input value k is too large.
See the code in Cuts.java.
You might also like to view...
From the time stamps recorded by ethereal, obtain the times it took to transfer the file with FTP and with TFTP. Use your knowledge of FTP, TFTP, TCP, and UDP to explain the outcome.
Include answers to the questions in Step 5.
What part of cloud computing refers to the use of Internet-based servers?
a. IaaS b. SaaS c. PaaS
When you make changes to a base style, ________
A) the base style and any styles based on it will all be updated B) only the base style will be updated C) you will be asked to choose whether or not you want styles based on it updated also D) a new style will be created with the change, but the base style itself will not change
An environment in which you create and edit Visual Basic for Applications code and procedures is the ________
Fill in the blank(s) with correct word