10930 - A-Sequence
Solution Description : Ad hoc Problem 1. If a[0]<1 then not an A-sequence. 2. If there's duplicate or if the input sequence is NOT in increasing order, then it's NOT an A-sequence. With that said, you do NOT have to sort the input. 3. If every ak of the sequence is the sum of two or more distinct earlier terms of the sequence then it's NOT ans A-sequence. earlier terms means-- Let be a sequence a1, a2, ..., an The earlier terms of an element ak, 1<=k<=n, there are the terms, a1, a2, ..., a(k-1) Example: 1 2 3 9 The earlier terms of 1 is nothing. The earlier terms of 2 is 1. The earlier terms of 3 are 1,2. The earlier terms of 9 are 1,2,3. 4. Instead of setting the array size as 30000, setting it to 1000 is enough because each number in the input sequence is <= 1000 anyways. |
||||||||||