-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchef_DEC_SANSKAR2.cpp
73 lines (52 loc) · 972 Bytes
/
chef_DEC_SANSKAR2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<math.h>
#define gc getchar
inline int scan()
{
register int n=0,c = gc();
while(c<48 || c>57)c=gc();
while(c>47 && c<58)n=(n<<1)+(n<<3)+c-48,c=gc();
return n;
}
int counter(int *arr, int n,int max)
{
int i,j,sum,count=0;
for(i=1;i<pow(2,n);i++) /// i=0 IS THE NULL SET
{
sum=0;
for(j=0;j<n;j++)
{
if((i & (1<<j))!=0)
sum+=arr[j];
}
if(sum==max)
{
count++;
}
}
return count;
}
int main()
{
int T,N,K,array[21],i,j,max,ans;
T=scan();
while(T--)
{
N=scan();
K=scan();
for(i=0;i<N;i++)
array[i]=scan();
max=array[0];
for(i=0;i<N;i++)
{
if(array[i]>max)
max=array[i];
}
ans=counter(array,N,max);
if(ans>=K)
printf("yes\n");
else
printf("no\n");
}
return 0;
}