Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <set>
- #include <cmath>
- #include <map>
- #include <string>
- #include <fstream>
- #include <queue>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- typedef long long ll;
- vector<int> a;
- vector<bool> flag;
- vector<int> ans;
- int res = 0;
- int n;
- void rec(int v) {
- if (v == n) {
- bool found = true;
- for (int i = 0; i < n; ++i) {
- if (ans[i] < i + 1)
- found = false;
- }
- if (found)
- ++res;
- return;
- }
- for (int i = 0; i < n; ++i) {
- if (!flag[i]) {
- flag[i] = true;
- ans.push_back(a[i]);
- rec(v + 1);
- flag[i] = false;
- ans.pop_back();
- }
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- in >> n;
- a.resize(n);
- flag.resize(n);
- for (int i = 0; i < n; ++i) {
- in >> a[i];
- }
- rec(0);
- out << res << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement