SubFibonacci
SRM 512 · 2011-05-25 · by fushar
Problem Statement
There is a collection of positive integers represented by
- Ash will pick some integers (possibly none or all) from S to form a subsequence of a Fibonacci sequence. The elements in Ash's subsequence don't have to follow in the same relative order as in S.
- Elsh will then perform the same action with the remaining integers of S.
- The resulting sequence will be Ash's subsequence concatenated with Elsh's subsequence, in that order.
Return the maximum possible number of integers that could be in the resulting sequence.
Notes
- A subsequence of a sequence is the result of removing some elements (possibly none or all) from the sequence, without changing the order of remaining elements.
Constraints
- S will contain between 1 and 50 elements, inclusive.
- Each element of S will be between 1 and 100,000,000, inclusive.
- All elements of S will be distinct.
Statement by TopCoder, Inc. — view the original on the archive.
{8, 1, 20, 3, 10}
Returns: 5
One possible solution is: Ash picks (1, 3, 8), which is a subsequence of (1, 1, 2, 3, 5, 8, 13). Elsh picks (10, 20). The resulting sequence is (1, 3, 8, 10, 20), containing 5 elements.
{19, 47, 50, 58, 77, 99}
Returns: 4
They can create a sorted sequence containing any 4 integers from S.
{512}
Returns: 1
One possible solution is: Ash picks (512). Elsh picks the empty sequence, (). The resulting sequence is (512), containing 1 element.
{3, 5, 7, 10, 13, 15, 20, 90}
Returns: 7
{1, 2, 3, 5, 8, 13, 21, 34, 55, 89}
Returns: 10
Submissions are judged against all 80 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SubFibonacci with a public method int maxElements(vector<int> S) · 80 test cases · 2 s / 256 MB per case