forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE0008.cpp
More file actions
39 lines (35 loc) · 649 Bytes
/
E0008.cpp
File metadata and controls
39 lines (35 loc) · 649 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
34
35
36
37
38
39
// Problem Code: MARCHA1
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
string payingUp(int m, vector<int> n){
int sum, subsetSize;
subsetSize = pow(2, n.size());
for(int i=0 ; i<subsetSize ; i++){
sum = 0;
for(int j=0 ; j<n.size() ; j++)
if(i & (1<<j))
sum += n[j];
if(sum == m)
return "Yes";
}
return "No";
}
int main()
{
int t, n, m, num;
vector<int> banknotes;
cin >> t;
for(int i=1 ; i<=t ; i++){
cin >> n >> m;
for(int j=0 ; j<n ; j++){
cin >> num;
banknotes.push_back(num);
}
cout << payingUp(m, banknotes) << endl;
banknotes.clear();
}
return 0;
}