Modulo Sum
Topic Abstract: Give you an array of integers, can you take out some trees, so that their and can be divisible by M.
Analysis: See code comments.
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMS =1000005;5 intN, M;6 intCnt[ms], R[ms], tem[ms];7 intMain () {8scanf"%d%d", &n, &m);9memset (CNT,0,sizeof(CNT));Ten for(inti =0; I < n; i++) { Onescanf"%d", &r[i]); AR[i]%=m; -cnt[r[i]]++;//count the number of different residues - } theMemset (R,0,sizeof(r));//initializing the remainder I cannot constitute - for(inti =0; I < m; i++) { - if(Cnt[i] >0) {//processing remainder I - intx =1; + while(Cnt[i] >0) { - inty = x < Cnt[i]?X:cnt[i]; +Cnt[i]-=y; AX *=2;//multiplication algorithm processing. at intz = (i * y)% m;//The y remainder i forms the remainder Z. - for(intj =0; J < M; J + +) { - if(R[j]) -tem[(j + z)% m] =1;//The remainder is formed on the basis of the remainder J (j + z)%m - } - for(intj =0; J < M; J + +) { inR[J] + = tem[j];//the remainder that the update can make -TEM[J] =0; to } +R[Z] =1;//The remainder Z can constitute - } the if(r[0] >0) * Break; $ }Panax Notoginseng } - if(r[0] >0) theprintf"yes\n"); + Else Aprintf"no\n"); the return 0; +}
CF 319 Div 2 Modulo Sum number theory +DP