fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. const int N = 30 ;
  4. int n ;
  5. int c[N][N] ;
  6. int choose[N] ;
  7. int ans[N] ;
  8. int used[N] ;
  9. int res = 1e9 ;
  10. void dq ( int id , int curc ){
  11. if ( curc >= res )
  12. return ;
  13. if ( id == n ){
  14. res = curc ;
  15. for ( int i = 0 ; i < n ; i++ )
  16. ans[i] = choose[i] ;
  17. return ;
  18. }
  19. for ( int i = 0 ; i < n ; i++ ){
  20. if ( !used[i] ){
  21. choose[id] = i + 1 ;
  22. used[i] = 1 ;
  23. dq( id + 1 , curc + c[id][i]) ;
  24. used[i] = 0 ;
  25. }
  26. }
  27. }
  28. int main(){
  29. cin >> n ;
  30. for ( int i = 0 ; i < n ; i++){
  31. for ( int j = 0 ; j < n ; j++ ){
  32. cin >> c[i][j] ;
  33. }
  34. }
  35. dq( 0 , 0 ) ;
  36. cout << res << endl ;
  37. for ( int i = 0 ; i < n ;i++ )
  38. cout << ans[i] << " " ;
  39. }
  40.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
0