Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAX = 22;
- int v, n;
- int coin[MAX];
- vector<int> sums;
- int32_t main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> v >> n;
- for(int i = 0; i < n; i++)
- cin >> coin[i];
- for(int i = 0; i < (1 << n); i++) {
- int s = 0;
- for(int j = 0; j < n; j++)
- if(i & (1 << j))
- s += coin[j];
- sums.push_back(s);
- }
- sort(sums.begin(), sums.end());
- if(binary_search(sums.begin(), sums.end(), v))
- cout << "S\n";
- else
- cout << "N\n";
- return 0;
- }
Add Comment
Please, Sign In to add comment