Data Structures & AlgorithmsVery hard

How many ways can [1, 2, 3, 4, 5, 7] be cut into one or more contiguous, non-empty segments so that EVERY segment has an even sum?

  1. A. 32
  2. B. 16
  3. C. 4
  4. D. 0

Correct answer: C. 4

Enumerate the 2^(n−1) cut positions and keep the cuts where every piece has even sum. The unrestricted count is 2^(n−1), and dropping the last element or restricting the number of cuts each gives a different total.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic