Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int a[20];
- int n;
- bool check(){
- for(int i=0; i<n; ++i )
- for(int k= i+1; k<n ; ++k )
- if(abs(k-i) == abs(a[k]-a[i]))
- return false;
- return true;
- }
- int main(){
- int ans = 0;
- cin >> n;
- for(int i=0; i<n ; ++i )
- a[i] = i;
- do{
- if(check())
- ++ans;
- }while(next_permutation(a, a+n));
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement