Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream fin("harti.in") ;
  4. ofstream fout("harti.out") ;
  5.  
  6. int n , cnt = 0 , c , X[11] , A[11][11] ;
  7. const int track = 1 ;
  8.  
  9. void Citire() ;
  10. void Afisare() ;
  11. void Back( int k ) ;
  12. bool Ok( int k ) ;
  13.  
  14. int main()
  15. {
  16. Citire() ;
  17. //X[1] = 1 ;
  18. //Back(track+1) ;
  19. Back(track) ;
  20. return 0;
  21. }
  22.  
  23. bool Ok( int k )
  24. {
  25. for( int i = 1 ; i < k ; i++ )
  26. if( X[i] == X[k] && A[k][i] == 1 ) return false ;
  27. return true ;
  28. }
  29.  
  30. void Back( int k )
  31. {
  32. if( k == n + 1 )
  33. {
  34. Afisare() ;
  35. }
  36. else
  37. {
  38. for( int i = 1 ; i <= c ; i++ )
  39. {
  40. X[k] = i ;
  41. if( Ok(k) )
  42. Back(k+1) ;
  43. }
  44. }
  45. }
  46.  
  47. void Citire()
  48. {
  49. int m , x , y ;
  50. fin >> n >> c >> m ;
  51. for( int i = 1 ; i <= m ; i++ )
  52. {
  53. fin >> x >> y ;
  54. A[x][y] = A[y][x] = 1 ;
  55. }
  56. }
  57.  
  58. void Afisare()
  59. {
  60. for( int i = 1 ; i <= n ; i++ )
  61. fout << X[i] << " " ;
  62. fout << '\n' ;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement