The number of n in a set of numbers, so that the sum of n equals a given value M

Source: Internet
Author: User

"topic analysis" in a set of numbers whether there is n number, so that the sum of n is equal to a given value m.

"Thinking Analysis": Analysis of data in the case:

1): 0 < n <= 100000

2): 0 < sequence length <= 100000

3): 0 <= m <=100000

Data is small: with a similar idea of DP,

Code:

#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream>using namespace STD; #define REP (i,j,k) for (int i= (int) j;i< (int.) k;++i) #define PER (i,j,k) for (int i= (int) j;i> (int) k;--i) #define Lowbit (a) A&-a#define Max (A, B) a>b?a:b#define Min (A, B) a>b?b:a#define mem (A, B) memset (A,b,sizeof (a)) typedef Long long ll;typedef unsigned long long llu;typedef double db;const int n=1e5+10;const int inf=0x3f3f3f3f;int t,n,m;int PR    E[n],last[n];int Num[n];int Main () {int x=0;    Char ch;    int sum=1;    MEM (last,0);        while (~ (Ch=getchar ())) {if (IsDigit (CH)) x=x*10+ch-' 0 ';            else if (ch!= ' \ n ') {pre[sum++]=x;        x=0;            } else{pre[sum++]=x;            MEM (last,0);            Last[0]=1;            M=read ();                    for (int i=1, i<sum; ++i) {for (int j=m; j>=0;--j) {int k=pre[i]+j;                if (last[j]&&k<=m) last[k]=1;    cout<< "k=" <<k<< "<<" Last[k "<<last[k]<<endl;            }} if (Last[m]) puts ("Yes");            Else puts ("No");            x=0;            Sum=1;        MEM (last,0); }} return 0;}


The number of n in a set of numbers, so that the sum of n equals a given value M

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.