Skip to content

Instantly share code, notes, and snippets.

@Noobgam Noobgam/pruning.cpp Secret
Created Mar 23, 2019

Embed
What would you like to do?
#pragma GCC optimize("Ofast")
#pragma comment(linker, "/stack:200000000")
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <map>
using namespace std;
const int N = 5100;
const int MOD = 1e9 + 7;
vector <int> now;
set <vector<int>> vis;
void cur(vector <int> stuff) {
if (stuff.empty()) {
reverse(now.begin(), now.end());
for (auto x : now) {
cout << x << "\n";
}
exit(0);
}
if (vis.count(stuff)) {
return;
}
vis.insert(stuff);
vector <int> check = stuff;
sort(check.begin(), check.end());
for (int i = 0; i < check.size(); ++i) {
if (check[i] > i + 1) {
return;
}
}
for (int i = 0; i < stuff.size(); ++i) {
if (stuff[i] > i + 1) {
return;
}
}
for (int i = stuff.size() - 1; i >= 0; --i) {
if (stuff[i] == i + 1) {
vector <int> stuff2 = stuff;
stuff2.erase(stuff2.begin() + i);
now.push_back(i + 1);
cur(stuff2);
now.pop_back();
}
}
}
int main() {
::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector <int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
cur(v);
cout << -1 << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.