提交时间:2023-10-28 08:55:37
运行 ID: 107720
# include <iostream> using namespace std ; int cnt = 0 , num ; bool isn [10] = { true , true , true , true , true , true , true , true , true , true } ; int pl [10] ; void dfs ( int k ) { if ( k == num ) { for ( int i = 1 ; i < num ; i ++ ) { cout << pl [i] ; } for ( int i = 1 ; i <= num ; i ++ ) { if ( isn [i] ) { cout << i ; } } cout << endl ; cnt ++ ; } for ( int i = 1 ; i <= num ; i ++ ) { if ( isn [i] ) { isn [i] = false ; pl [k] = i ; dfs ( k + 1 ) ; pl [k] = 0 ; isn [i] = true ; } } return ; } int main ( ) { cin >> num ; dfs ( 1 ) ; cout << cnt << endl ; }