fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main(){
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(0);
  8.  
  9. int t;
  10. cin >> t;
  11. while(t--){
  12. int n,cnt = 0;
  13. cin >> n;
  14. vector<int> a(n),tar(n);
  15. for(int i = 0; i <n;i++) cin >> tar[i];
  16.  
  17. for(int i = 0; i < n;i++)a[i] = i + 1;
  18.  
  19. do{
  20. cnt++;
  21. if(a == tar) break;
  22. }while(next_permutation(a.begin(),a.end()));
  23.  
  24. cout << cnt << "\n";
  25. }
  26. }
  27.  
Success #stdin #stdout 0.01s 5288KB
stdin
2
6 4
1 3 5 6
6 4
2 3 4 6
stdout
720
24