Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, k;
- vector<int> v;
- int mn;
- void rek(int indx, int cnt, int sum)
- {
- if (indx == n)
- return;
- if (sum == k && cnt < mn)
- mn = cnt;
- rek(indx + 1, cnt + 1, sum + v[indx]);
- rek(indx + 1, cnt, sum);
- }
- int main()
- {
- int t;
- cin >> t;
- while(t--)
- {
- mn = INT_MAX;
- int x;
- cin >> n >> k;
- for (int i = 0; i < n; i++)
- {
- cin >> x;
- v.push_back(x);
- }
- rek(0, 0, 0);
- if (mn == INT_MAX)
- cout << "impossible\n";
- else
- cout << mn << '\n';
- v.clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement