Noip2002-Universal Group Rematch-third question-select number

Source: Internet
Author: User

Title DescriptionDescription n integers known as x1,x2,..., xn, and an integer k (k<n). Add any of the k integers from n integers to get a series of sum. For example, when n=4,k=3,4 integers are 3,7,12,19, all combinations can be combined with their and:
3+7+12=22 3+7+19=29 7+12+19=38 3+12+19=34.
Now, ask you to figure out how many kinds of numbers are in total.
For example, in the above example, there is only one and a prime number: 3+7+19=29). input/output format input/output Input Format:
Keyboard input, in the form of:
N, K (1<=n<=20,k<n)
X1,X2,...,XN (1<=xi<=5000000)
output Format:
Screen output in the form of:
An integer (the number of species that satisfies the condition). input and Output sample sample Input/output sample Test point # # Input Sample:

4 3
3 7 12 19

Sample output:

1

Idea: Analog, not explained!

The code is as follows:

1 //use array input to save the flags used for each number, and use array A to save the entered numbers2#include <stdio.h>3#include <math.h>4#include <string.h>5 intsort=0, n,k,a[ +]; 6 intSushu (intX//is the prime number to return 1, not to return 07 {    8     intI,y; 9y=sqrt (x); Ten      for(i=2; i<=y;i++)     One         if(x%i==0)     A             return 0;  -     return 1;  - }     the voidFintInput[],intPosintM//f (Array to be manipulated, location, number of M selected) - {     -     if(m==0)     -     {     +         intj,sum=0;  -          for(j=0; j<n;j++)     +             if(input[j]==1)     Asum+=A[j];  at         if(Sushu (sum) = =1)     -sort++;  -         return;  -     }     -     Else     -     {     in         inti;  -          for(i=pos;i<n;i++)     to         {     +             if(input[i]==0)     -input[i]=1;  theF (input,i+1, M-1);  *input[i]=0;  $         }    Panax Notoginseng     }     -     return;  the }     + intMain () A {     the     intinput[ +],i;  +scanf"%d%d",&n,&k);  -      for(i=0; i<n;i++)     $scanf"%d",&A[i]);  $memset (Input,0,sizeof(int)* +);  -F (Input,0, K);  -printf"%d\n", sort);  the     return 0;  -}

Noip2002-Universal Group Rematch-third question-select number

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.