#include <bits/stdc++.h>
#include "molecules.h"
using namespace std;
bool hasResponse = false;
vector<int> solution(int currInd, int currSum, vector<int> &currArray, int u, int l, int n, vector<int> &w) {
if (hasResponse) {
return vector<int>(0);
}
if (currSum > u) {
return vector<int>(0);
}
if (currInd == n && l <= currSum && currSum <= u) {
hasResponse = true;
return currArray;
} else if (currInd == n) {
return vector<int>(0);
}
// cout << currInd << " " << currSum << endl;
if (0 <= currInd && currInd < n) {
currSum += w[currInd];
}
for (int ind = currInd + 1; ind <= n; ind++) {
if (ind != n)
currArray.push_back(ind + 1);
vector<int> currResponse = solution(ind, currSum, currArray, u, l, n, w);
if (currResponse.size() != 0) {
hasResponse = true;
return currResponse;
}
currArray.pop_back();
}
return vector<int>(0);
}
vector<int> find_subset(int l, int u, vector<int> w) {
int n = w.size();
vector<int> arr;
vector<vector<int> > memo;
memo.resize(n, vector<int>(u + 1, -1));
return solution(-1, 0, arr, u, l, n, w);
}
// int main() {
// vector<int> res;
// res = find_subset(15, 17, {-1, 8, 8, 7});
// for (auto l: res) {
// cout << l << " ";
// }
// cout << endl;
// }
Compilation message (stderr)
molecules.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |