RT,大佬们帮忙看看哪里出问题了
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, bool>> weight(0);
vector<int> choice(0);
int tempWeight = 0;
void dfs(int last)
{
bool existPlace = false;
for (auto &k : weight)
{
if (!k.second && k.first <= last){
existPlace = true;
break;
}
}
if (existPlace == false)
{
if (count(choice.begin(), choice.end(), tempWeight) == 0)
choice.push_back(tempWeight);
return;
}
for (auto &j : weight)
{
if (!j.second && j.first <= last)
{
tempWeight += j.first;
j.second = true;
dfs(last - j.first);
tempWeight -= j.first;
j.second = false;
}
}
}
int main()
{
int n, c;
cin >> n >> c;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
weight.push_back({temp, false});
}
dfs(c);
int max_weight = 0;
for (auto &q : choice)
{
max_weight = max(max_weight, q);
}
cout << max_weight << endl;
return 0;
}