Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int a[100][100],n,m,x[100];
  5. void citire()
  6. {
  7. int i,j;
  8. ifstream f("grafpapy.txt");
  9. f>>n>>m;
  10. for(i=1;i<=n;i++)
  11. {
  12. for(j=1;j<=n;j++)
  13. f>>a[i][j];
  14. }
  15.  
  16. }
  17. struct muchie{int x,y;};
  18. muchie l[100];
  19. void lista_muchii()
  20. {
  21. int i,j,k=0;
  22. for(i=1;i<=n;i++)
  23. for(j=1;j<=i-1;j++)
  24. if(a[i][j]==1)
  25. {
  26. k++;
  27. l[k].x=i;
  28. l[k].y=j;
  29. }
  30. }
  31. int cond(int k)
  32. {
  33. if(k>1&&x[k]<=x[k-1])
  34. return 0;
  35. else return 1;
  36. }
  37. int sol(int k,int nr)
  38. {
  39. return (k==nr);
  40. }
  41. void afisare(int k,int nr)
  42. {
  43. int i,j,b[100][100];
  44. cout<<endl;
  45. for(i=1;i<=n;i++)
  46. for(j=1;j<=n;j++)
  47. b[i][j]=0;
  48. for(i=1;i<=nr;i++)
  49. {
  50. b[l[x[i]].x][l[x[i]].y]=1;
  51. b[l[x[i]].y][l[x[i]].x]=1;
  52. }
  53. for(i=1;i<=n;i++)
  54. {
  55. for(j=1;j<=n;j++)
  56. cout<<b[i][j]<<" ";
  57. cout<<endl;
  58. }
  59. }
  60. void back(int nr)
  61. {
  62. int gasit,k=1;
  63. x[k]=0;
  64. while(k>0)
  65. {
  66. gasit=0;
  67. while(gasit==0&&x[k]<m)
  68.  
  69. {
  70. x[k]++;
  71. if(cond(k)==1)
  72. gasit=1;
  73. }
  74. if(gasit==0)
  75. k--;
  76. else
  77. if(sol(k,nr)==1)
  78. afisare(k,nr);
  79. else
  80. {
  81. k++;
  82. x[k]=0;
  83. }
  84. }
  85. }
  86. int main()
  87. {
  88. int i;
  89. citire();
  90. lista_muchii();
  91. for(i=0;i<=m;i++)
  92. back(i);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement