-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBruteForce.cpp
More file actions
33 lines (29 loc) · 837 Bytes
/
BruteForce.cpp
File metadata and controls
33 lines (29 loc) · 837 Bytes
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
#include<stdio.h>
#include<math.h>
int main(){
int t,m,n,temp=0;
scanf("%d",&t);
while(t>0){
int flag=0;
scanf("%d",&n);
scanf("%d",&m);
int a[n];
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<pow(2,n);i++)
{
temp=0;
for(int j=0;j<n;j++){
if(i&1<<j)
temp+=a[j];
}
if(m==temp){flag=1;break;}
}
if(flag==1){printf("Yes");break;}
else
printf("No\n");
t--;
}
return 0;
}