C++: A string construction problem defined as follows:
- You are given as input a target string
- Starting with an empty string, you add characters to it, until your new string is same as the target. You have two options to add characters to a string:
- You can append an arbitrary character to your new string, with cost x
- You can clone any substring of your new string so far, and append it to the end of your new string, with cost y
- For a given target, append cost x, and clone cost y, we want to know what the *cheapest cost* is of building the target string
For some simple examples:
- Target "aa", append cost 1, clone cost 2: the cheapest cost is 2:
- Start with an empty string, ""
- Append 'a' (cost 1), giving the string "a"
- Append 'a' (cost 1), giving the string "aa"
- Target "aaaa", append cost 2, clone cost 3: the cheapest cost is 7:
- Start with an empty string, ""
- Append 'a' (cost 2), giving the string "a"
- Append 'a' (cost 2), giving the string "aa"
- Clone "aa" (cost 3), giving the string "aaaa"
- Target "xzxpzxzxpq", append cost 10, clone cost 11: the cheapest cost is 71:
- Start with an empty string, ""
- Append 'x' (cost 10): "x"
- Append 'z' (cost 10): "xz"
- Append 'x' (cost 10): "xzx"
- Append 'p' (cost 10): "xzxp"
- Append 'z' (cost 10): "xzxpz"
- Clone "xzxp" (cost 11): "xzxpzxzxp"
- Append 'q' (cost 10) : "xzxpzxzxpq"
In the file `StringConstruction.h` implement a function `stringConstruction` that takes the target string, the clone cost, and the append cost (in that order), and returns the cheapest way of making the target string. It doesn't need to return *how* to do it, just the cost.
To test your code, TestStringCons.cpp contains some test cases.
Note: it will need to work for the largest of these target strings, which is 30,000 characters. the code will be ran on a modest desktop PC, and allowed 2 seconds.
StringConstruction.h file:
#ifndef STRINGCONSTRUCTION_H
#define STRINGCONSTRUCTION_H
#include <string>
using std::string;
// TODO: your code goes here:
// do not write or edit anything below this line
#endif
TestStringCons.cpp file:
#include "StringConstruction.h"
#include <iostream>
using std::cout;
using std::endl;
using std::ostream;
#include <vector>
using std::vector;
struct Testcase {
string target;
int appendCost;
int cloneCost;
int bestCost;
string notes;
};
ostream & operator<<(ostream & o, const Testcase & t) {
o << "Target string: " << t.target << "\n";
o << "Cost of appending an arbitrary character: " << t.appendCost << "\n";
o << "Cost of cloning a substring, and appending: " << t.cloneCost << "\n";
o << "Cheapest way to make the string should be: " << t.bestCost << "\n";
return o;
}
int main() {
int retval = 0;
vector<Testcase> testcases{
{"aa",1,2,2," Append 'a' (cost 1), append 'a' (cost 1)"},
{"aaaa",2,3,7," Append 'a' (cost 2), append 'a' (cost 2), clone 'aa' (cost 3)"},
{"xzxpzxzxpq", 10, 11, 71, " Append 'x' (cost 10), Append 'z' (cost 10), Append 'x' (cost 10), Append 'p' (cost 10), Append 'z' (cost 10),\n Clone 'xzxp' (cost 11), Append 'q' (cost 10)"}
};
for (size_t i = 0; i < testcases.size(); ++i) {
cout << "Testcase " << i << "\n";
cout << testcases[i];
cout << "\nRunning your function\n";
int costWas = stringConstruction(testcases[i].target, testcases[i].cloneCost, testcases[i].appendCost);
if (costWas == testcases[i].bestCost) {
cout << " -- Test passed, correct cost was returned\n\n\n";
} else {
cout << " -- Test failed, incorrect cost of " << costWas << " was returned\n";
cout << " To help your debugging, the cheapest way to make the string should be:\n";
cout << testcases[i].notes << "\n\n\n";
++retval;
}
}
string bigString = "abcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifpblgmbtmblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifpblgmbtmblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcqaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifpblgmbtmblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjoirmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifpblgmbtmblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipiblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifpblgmbtmblgmbaipfdmbcntdblgblgmbaipmbcntdblgblgmbaipcbcntdblgblgmbaipobacjodblgblgmbaiabcblgmbcntdblgblgmbaipmbcntdblgblgmbaipfdmbcqaipfdmbcntdblgblgmbaipmbcntdblgblgmbaiprtifbcntdblgblgmbaipmbcntdblgblgmbaip";
string doubleIt = bigString + bigString;
cout << "Big target string testcase, using a " << doubleIt.size() << " character test string. An excellent solution will complete in around a hundredth of a second.\n";
cout << "(Note -- if the program freezes at this point, Ctrl+C will stop it from running)\n";
int result = stringConstruction(doubleIt, 1235, 1234);
if (result == 59249) {
cout << "-- Correct cost of 59249 returned\n";
} else {
cout << "-- Incorrect cost of " << result << " returned, rather than 59249\n";
}
return retval;
}
In: Computer Science
A factory manufactures alloy rods for construction companies. The lengths of rods are uniformly distributed with minimum of 80 and maximum of 120 cm. Find the 80th percentile of the length of the rods. Find the probability a rod is less than 101.4 cm long. Find the probability a rod is more than 102.5 cm long. Given that the rod is more than 101 cm, find the probability it is longer than 99 cm. Given that the rod is more than 101 cm, find the probability it is less than 103 cm.
In: Statistics and Probability
|
A construction company in Naples, Florida, is struggling to sell condominiums. In order to attract buyers, the company has made numerous price reductions and better financing offers. Although condominiums were once listed for $300,000, the company believes that it will be able to get an average sale price of $207,000. Let the price of these condominiums in the next quarter be normally distributed with a standard deviation of $13,000. Use Table 1. |
| a. |
What is the probability that the condominium will sell at a price (i) Below $182,000?, (ii) Above $228,000? (Round "z" value to 2 decimal places and final answer to 4 decimal places.) |
| Probability | |
| Below $182,000 | |
| Above $228,000 | |
| b. |
The company is also trying to sell an artist’s condo. Potential buyers will find the unusual features of this condo either pleasing or objectionable. The manager expects the average sale price of this condo to be the same as others at $207,000, but with a higher standard deviation of $17,000. What is the probability that this condo will sell at a price (i) Below $182,000?, (ii) Above $228,000? (Round your answers to 4 decimal places.) |
| Probability | |
| Below $182,000 | |
| Above $228,000 | |
In: Statistics and Probability
Anderson Metals manufactures and sells #3 steel rebar that is used in the construction of slabs and driveways. The steel bar not only strengthens the finished concrete product, but it also has unique properties such that its temperature related expansion and contraction matches that of concrete. The product is manufactured and sold in 20' long "sticks." The product is generally produced and sold to match customer demand, and there is not a significant amount of finished goods inventory at any point in time. Summary information for 20X6 is as follows: Sales were $20,000,000, consisting of 5,000,000 sticks. Total variable costs were $11,000,000. Total fixed costs were $8,000,000. Net income was $1,000,000. The general economic conditions appear to be deteriorating heading into 20X7, and there is some concern about a reduction in sales volume. The following questions should each be answered independent of one another. 1. (a) What is the company's break-even point in "sticks?" Can the company sustain a 30% reduction in total volume, and remain profitable? 2. (b) The company's sole shareholder, Doug Anderson, generally lives off of dividends paid by the business. The business typically declares and pays a dividend equal to 25% of net income. If Doug needs to receive $100,000 in dividends for normal living expenses, what total revenues must Anderson Metals produce in 20X7? 3. (c) If total volume is expected to decrease by 20%, and the company wishes to continue to produce a $1,000,000 net income by raising the per unit selling price, what revised per stick price must be imposed? Will this strategy necessarily work? 4. (d) If the company expects a drop in raw material prices to reduce total variable costs to $2 per stick, but all other revenue and cost factors to be unaffected, what will be the revised break-even point in sales and units?
In: Accounting
You are the Chief Finance officer for Mazembe Limited, A company engaged in construction of apartments for third parties. Mazembe has 200 employees in total and the following transactions have arisen that require you advise on how they should be reported.
The first receivable is for K400 million. In return for assigning the receivable, Mazembe has received K360 million from the factor. Under the terms of the factoring arrangement, Mazembe will not have to repay this money, even if the customer does not settle the debt.
The second receivable is for K200 million. In return for assigning the receivable, Mazembe has received K140 million from the factor. The terms of this factoring arrangement state that Mazembe will receive a further K10 million if the customer settles the account on time. If the customer does not settle the account in accordance with the agreed terms then the receivable will be reassigned back to Mazembe who will then be obliged to refund the factor with the original K140 million.
On 31 December 2019, Mazembe received its fixed interest. However, it estimated that the probability of default on the bond within the next 12 months would be 0.8%. if default occurs within the next 12 months, Mazembe estimates that no further interest would be received and that only 30% of capital will be repaid on 31 December 2022.
Required:
Discuss in detail, with relevant computations, the required accounting treatment of each of the above transactions for the year ended 31 December 2019. Summarize your discussion on each item in financial statement extracts.
Total
In: Accounting
Hafners Construction is analyzing its capital expenditure proposals for the purchase of equipment in the coming year. The capital budget is limited to $15,000,000 for the year. Lauren Bobo,staff analyst at Hafners, is preparing an analysis of the three projects under consideration by Caden Hafners, the company's owner.
Project A
Project B
Project C
Projected cash outflow
Net initial investment
$6,600,000
$8,500,000
$9,000,000
Projected cash inflows
Year 1
$3,600,000
$5,500,000
$4,900,000
Year 2
3,600,000
2,000,000
4,900,000
Year 3
3,600,000
1,100,000
200,000
Year 4
3,600,000
100,000
Required rate of return
6%
6%
6%
In: Accounting
|
Johnson Company is preparing a bid on a new construction project. Two other contractors will be submitting bids for the same project. |
|||||||||||||||||||||
|
Based on past bidding practices, bids from other contractors can be described by the following probability distributions: |
|||||||||||||||||||||
|
Contractor A: Uniform probability distribution between $500,000 and $1,000,000. |
|||||||||||||||||||||
|
Contractor B: Normal probability distribution with a mean bid of $700,000 and a standard deviation of $100,000. |
|||||||||||||||||||||
|
a. If Johnson Company submits a bid of $750,000, what is the probability Butler will obtain the bid. Simulate 1000 trials of the contract bidding process. Note: Johnson's bid must be less than BOTH A and B. |
|||||||||||||||||||||
In: Statistics and Probability
B05 - Construction Surveying - Assignment 8
Explain the process for establishing the line and grade for a sanitary sewer line connection to an existing municipal sanitary manhole. Include the type of sewer flow, the importance of the pipe invert and reach of the sewer in determining the slope of the pipe, factors that determine the use of manholes, the use of batter boards and offset stakes, minimum ground cover required. In addition, discuss the use of visual aid such as field notes and a simple plan and profile drawing in establishing the line and grade.
the previous answer in wrong / incomplete
In: Civil Engineering
Contracts for two construction jobs are randomly assigned to one or more of three firms A, B, and C. Let Y1 denote the number of contracts assigned to firm A and Y2 the number of contracts assigned to firm B. Recall that each firm can receive 0, 1 or 2 contracts.
(b) Find the marginal probability of Y1 and Y2.
(c) Are Y1 and Y2 independent? Why? (d) Find E(Y1 − Y2).
(e) Find Cov(Y1, Y2)
In: Math
Suppose that Caterpillar Incorporated is considering a new line of construction graders. To launch the new product, Caterpillar will have to invest $200.00 million. The target capital structure for Caterpillar is 45.00% debt and 55.00% equity (market values).
The CFO for the company believes that new debt can be issued with an 8.00% annual coupon rate. After reviewing the company’s beta, the CFO also believes that common stockholders require a 15.00% return for the new investment.
The company projects an annual after-tax cash flow of $65.00 million for the new project. The company has a marginal tax rate of 35.00%, and expects to run the project for 10.00 years.
What is the NPV for the project?(express in millions)
In: Finance