CF 319 Div 2 Modulo Sum number theory +DP

Source: Internet
Author: User

                  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

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.