Finds the sub-array of the given array, the Subarray and exactly the given target number t----dynamic planning/recursion/search (pending completion)

Source: Internet
Author: User

Write a function, passing in an array of int, to return whether the array can be divided into two groups, so that the elements in the two groups are added together and equal, and that all multiples of 5 must be in one group, and all multiples of 3 in another group (not including a multiple of 5), can satisfy the above conditions, return True ; returns false when not satisfied.

Input Description:

The first line is the number of data, the second row is the input data

Output Description:

Returns TRUE or False

Input Example:
41 5-5 1

Output Example:

True
v1=Int (raw_input ()) V2=raw_input (). Split (' ') V2=Map (int,v2) a=[]b=[]c=[] forIinchV2:ifI%3==0 andi%5!=0:a.append (i)elifi%5==0:b.append (i)Else: C.append (i) A1=sum (a) B1=sum (b) C1=sum (c) DIF=abs (a1-B1)#X-y=dif#X+Y=C1x= (DIF+C1)%2y= (c1-dif)%2ifX==0 andY==0:## #如果x, y is 0, that is, X1 has an integer solution, it is possible to find an array that satisfies the result, and next is to determine, in a or B, whether to find the sub-array and exactly the X1x1= (DIF+C1)/2C1=Sorted (c1) Ads=0 Lis=[] I=0 whileads<=x1:lis.append (C1[i]) ads+=C1[i] I+=1Print 'true'Else:    Print 'false'

Finds the sub-array of the given array, the Subarray and exactly the given target number t----dynamic planning/recursion/search (pending completion)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.