#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define dbg(x) cout << #x << " = " << (x) << endl;
//const int INF = 1e18;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
int best_count = 0;
vector<int> best_path;
void dfs(int tokens, vector<bool>& used, const vector<int>& P, const vector<int>& T, vector<int>& path) {
bool progressed = false;
int N = P.size();
for (int i = 0; i < N; ++i) {
if (!used[i] && tokens >= P[i]) {
int new_tokens = (tokens - P[i]) * T[i];
used[i] = true;
path.push_back(i);
dfs(new_tokens, used, P, T, path);
path.pop_back();
used[i] = false;
progressed = true;
}
}
if (!progressed) {
if ((int)path.size() > best_count) {
best_count = path.size();
best_path = path;
}
}
}
vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T) {
int N = P.size();
best_count = 0;
best_path.clear();
vector<bool> used(N, false);
vector<int> path;
dfs(A, used, P, T, path);
return best_path;
}
/*int32_t main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("input.in", "r", stdin);
//freopen("input.out", "w", stdout);
vector<int> ans = max_coupons(13, {4, 500, 8, 14}, {1, 1, 1, 1});
for(auto x : ans) cout<<x<<endl;
return 0;
}*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |