Untitled
raw download clone
C
views 59
,
size 440 b
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int a[100005] = {0};
int NUM(int id, int sum, int n, int k){
    if(sum == k) return 1;
    if( id>=n && sum > k) return 0;
    return NUM(id+1,sum+a[id], n, k)+ NUM(id+1, sum, n, k);
}
int main( ){
    int n, k, i;              
    scanf("%d%d", &n, &k);
    for(i=1;i<=n;i++){
        scanf("%d", &a[i]);
    }
    printf("%d\n", NUM(0,0, n, k));
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.