AlmostFibonacciKnapsack
SRM 687 · 2016-04-01 · by lg5293
Problem Statement
You are given a sequence of integers. This sequence is defined as follows:
- A[1] = 2
- A[2] = 3
- for each n >= 3, A[n] = A[n-1] + A[n-2] - 1
You are given a
- The elements of B are distinct positive integers.
- x = A[B[0]] + A[B[1]] + ... + A[B[k-1]], where k is the number of elements in B.
If there are multiple solutions, return any of them.
If there are no solutions, return the
Constraints
- x will be between 2 and 10^18, inclusive.
148
Returns: {6, 10, 8, 5 }
The first few terms of the sequence are 2,3,4,6,9,14,22,35,56,90. We can see that 14+90+35+9=148, and their respective indices are 6,10,8,5.
2
Returns: {1 }
13
Returns: {2, 3, 4 }
3
Returns: {2 }
86267769395
Returns: {3, 14, 15, 9, 26, 53, 5, 8 }
Submissions are judged against all 120 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlmostFibonacciKnapsack with a public method vector<int> getIndices(long long x) · 120 test cases · 2 s / 256 MB per case