23A Section Handout Addendum
23A Section Handout Addendum
Your routine should return as soon as it can produce a true or false, as all of our
recursive backtracking examples have.
struct interval {
int start;
int end;
};
struct movie {
string name;
int duration; // in minutes
Vector<int> showTimes; // each in minutes since midnight
};
8 – 6 * 2 – 4 equals 0
Given the numbers 1, 4, 7, and 9, we can form the number 20. Here’s how:
4 – 1 * 9 – 7 equals 20
Note that all operators have equal precedence, and no parentheses are allowed.
Write the combine function, which takes a Vector<int> of numbers and a target value
and returns true if and only if all of the operands can be combined using equal-precedent
addition, subtraction, and multiplication to form the given target. By equal precedent, we
mean don’t respect the normal order of operations where multiplication takes higher
precedence than addition and subtraction. Just assume all expressions are evaluated from
left to right (so that, for example, 4 – 2 * 2 is 4 and not 0.)
static bool combine(Vector<int>& numbers, int target);
0 1 2 3 4 5
you should be able to permute and rotate as necessary in
order to discover the arrangement on the right.
what the solution is. You only need to return a yes or a no.