Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector <int> polje;
- int T , n , k , a , mini=10000;
- void rek(int x ,int sum , int prov , int broj){
- if (x>=n) return;
- if (prov && sum<k){
- sum+=polje[x];
- broj++;
- }
- if (sum==k && broj<mini) mini=broj;
- rek(x+1,sum,0,broj);
- rek(x+1,sum,1,broj);
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(0);cout.tie(0);
- cin>>T;
- for (int i=0;i<T;i++){
- mini=10000;
- cin>>n>>k;
- for (int j=0;j<n;j++){
- cin>>a;
- polje.push_back(a);
- }
- rek(0,0,0,0);
- rek(0,0,1,0);
- if (mini==10000) cout<<"impossible \n";
- else cout<<mini<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement