Untitled
raw download clone
C
views 14
,
size 481 b
#include <stdio.h>

int n, k;
int a[21];
int num(int id, int sum);

int main(void)
{
    scanf("%d %d", &n, &k);
    for (int i = 0;i < n;i++)
    {
        scanf("%d", &a[i]);
    }
    printf("%d\n", num(0, 0));

    return 0;
}

int num(int id, int sum)
{
    if (sum == k)
    {
        return 1;
    }
    if (id >= n || sum > k)
    {
        return 0;
    }
    else
    {
        return num(id + 1, sum + a[id]) + num(id + 1, sum);
    }
}
close fullscreen
Login or Register to edit or fork this paste. It's free.