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