3531: Divide the judgment

Source: Internet
Author: User

3531: Divide by judgment

    • View
    • Submit
    • Statistics
    • Questions

Total time limit:

1000ms

Memory Limit:

65536kB

Describe

A given sequence of positive integers, after which each number is inserted with a + sign or-number after calculating their and. For example, sequence: 1, 2, 4 There are 8 possible sequences:
(+1) + (+2) + (+4) = 7
(+1) + (+2) + (-4) =-1
(+1) + (-2) + (+4) = 3
(+1) + (-2) + (-4) = 5
(-1) + (+2) + (+4) = 5
(-1) + (+2) + (-4) = 3
(-1) + (-2) + (+4) = 1
(-1) + (-2) + (-4) = 7
At least one of the results can be divisible by an integer k, which we call a sequence of integers divisible by K. For example, the above sequence can be divisible by 3, 5, 7, and not by 2, 4, 6, 8 ... Divisible. Note: 0,-3,-6,-9 ... can be considered as multiples of 3.

Input

The first line of input contains two numbers: N (2 < N < 10000) and K (2 <k< 100), where n represents a total n number, and K represents the divisor. The second line gives the n integers in the sequence, with values ranging from 0 to 10000 (possibly duplicates).

Output

If this positive integer sequence can be divisible by K, the output is yes, otherwise the output is no. (Note: all uppercase letters)

Sample input

3 2

1 2 4

Sample output

NO

/*f (i,j) indicates the number of pre-I and can%k (I,J) can be obtained from two cases (only add and subtract): The first i-1 number of and +a[i]: F (i-1, (k+j-a[i]%k)%k) before the i-1 and-a[i]: F (i-1, (k+j+a[i) %K)%k)*/#include<cstdio>#defineRef (I,X,Y) for (int i=x;i<=y;i++)using namespacestd;intn,k,a[10100];BOOLf[10100][ the];intMain () {scanf ("%d%d",&n,&k); refI1, N) scanf ("%d",&A[i]); f[0][0]=1; refI1, N)ref(J,0, K) f[i][j]=f[i-1[(k+j-a[i]%k)%k]| | f[i-1[(K+j+a[i]%k)%k];//bool | |, returnprintf"%s\n", f[n][0]?"YES":"NO"); return 0; }

3531: Divide the judgment

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.