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