why my code is giving wrong ans i know second way to sort indecending and get the combination of target but i tried same approach as its given there to give minimum plates and its giving wrong ans
include
include
include
using namespace std;
void solve(vector&v, vector¤t, vector&best, int target, int ind) {
if (ind == v.size()) {
if (target == 0 && (best.empty() || current.size() < best.size())) {
best = current;
}
return;
}
if (v[ind] <= target) {
current.push_back(v[ind]);
solve(v, current, best, target - v[ind], ind + 1);
current.pop_back();
}
solve(v, current, best, target, ind + 1);
}
int main() {
int t; cin>>t;
while(t–){
int n,target;
cin>>n>>target;
vector v(n);
for(int i=0;i<n;i++) cin>>v[i];
vector current;
vector best;
solve(v, current, best, target, 0);
cout << best.size()<<endl;
}
return 0;
}