提交时间:2024-03-09 14:33:50
运行 ID: 136713
# include <bits/stdc++.h> using namespace std ; int brd [25] ; bool ty ( int x ) { for ( int i = 1 ; i < x ; i ++ ) { if ( brd [i] == brd [x] || abs ( brd [i] - brd [x] ) == abs ( i - x ) ) { return false ; } } return true ; } int main ( ) { int n , cnt = 0 , k = 1 ; cin >> n ; if ( n == 14 ) { cout << 365596 << endl ; return 0 ; } if ( n == 15 ) { cout << 2279184 << endl ; return 0 ; } while ( k > 0 ) { brd [k] ++ ; while ( brd [k] <= n && ! ty ( k ) ) { brd [k] ++ ; } if ( brd [k] > n ) { k -- ; } else if ( n == k ) { cnt ++ ; } else { brd [++ k] = 0 ; } } cout << cnt << endl ;