Untitled
raw download clone
TEXT
views 31
,
size 467 b
#include <stdio.h>
int a[10000005];
int n, k,ans=0;
int num(int id, int sum)
{
    if(sum == k)
    {
        ans++;
        return 0;
    }
    else if(id >= n || sum > k)
        return 0;
    else
    {
        num(id+1,sum+a[id]);
        num(id+1, sum);
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    num(0,0);
    printf("%d\n",ans);
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.