#237. 分组求和:强制包含特定数字

    ID: 237 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatRecursion-2gesp5递归贪心

分组求和:强制包含特定数字

Group Sum (Must Include 6)

Background

Congcong is playing a number game. He has a list of integers and needs to select some of them such that their sum equals a given target value. However, there's a special rule: if the number 66 appears in the list, all occurrences of 66 must be selected.

Problem Description

Given an array of ints, is it possible to choose a group of some of the ints, beginning at the start index, such that the group sums to the given target? However, with the additional constraint that all 66's must be chosen. (No loops needed.)

Input Format

Input is given from standard input in the following format.

start nums target

Where start is an integer representing the starting index; nums is an array of integers; target is an integer representing the target sum.

Output Format

Output is printed to standard output in the following format.

true or false

Output true if a valid group of numbers can be chosen, otherwise output false.

Sample

0 [5 6 2] 8
true
0 [5 6 2] 9
false
0 [5 6 2] 7
false

Sample Explanation

For Sample 1: start = 0, nums = [5, 6, 2], target = 8. Since the array contains 66, 66 must be chosen. The remaining target is 86=28 - 6 = 2. From the remaining numbers [5,2][5, 2], choosing 22 achieves the target sum of 22. Thus, choosing 66 and 22 results in a sum of 88, so true is output.

Constraints

Time limit: 11 second, Memory limit: 10241024 KiB for each test case.