Advertisement
deushiro

Untitled

Feb 5th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <cmath>
  6. #include <map>
  7. #include <string>
  8. #include <fstream>
  9. #include <queue>
  10.  
  11. using namespace std;
  12.  
  13. ifstream in("input.txt");
  14. ofstream out("output.txt");
  15.  
  16. typedef long long ll;
  17.  
  18. vector<int> a;
  19. vector<bool> flag;
  20. vector<int> ans;
  21. int res = 0;
  22. int n;
  23.  
  24. void rec(int v) {
  25.     if (v == n) {
  26.         bool found = true;
  27.         for (int i = 0; i < n; ++i) {
  28.             if (ans[i] < i + 1)
  29.                 found = false;
  30.         }
  31.         if (found)
  32.             ++res;
  33.         return;
  34.     }
  35.     for (int i = 0; i < n; ++i) {
  36.         if (!flag[i]) {
  37.             flag[i] = true;
  38.             ans.push_back(a[i]);
  39.             rec(v + 1);
  40.             flag[i] = false;
  41.             ans.pop_back();
  42.         }
  43.     }
  44. }
  45.  
  46.  
  47. int main()
  48. {
  49.     ios_base::sync_with_stdio(false);
  50.     cin.tie(0);
  51.     cout.tie(0);
  52.     in >> n;
  53.     a.resize(n);
  54.     flag.resize(n);
  55.     for (int i = 0; i < n; ++i) {
  56.         in >> a[i];
  57.     }
  58.     rec(0);
  59.     out << res << endl;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement