12137 - Johnny Johnny
raw download clone
C
views 32
,
size 446 b
#include <stdio.h>

int n, k;
int a[21] = {0};
int count(int pos, int sum);

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

    return 0;
}

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