Advertisement
Guest User

Generare Graf

a guest
Apr 8th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. //ALEX ENACHE
  2.  
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. #include <math.h>
  7. #include <iomanip>
  8. #include <bitset>
  9.  
  10. #include <queue>
  11. #include <deque>
  12. #include <stack>
  13. #include <string>
  14.  
  15. #include <map>
  16. #include <unordered_map>
  17. #include <set>
  18. #include <unordered_map>
  19.  
  20. #include <random>
  21. #include <time.h>
  22. #include <assert.h>
  23. #include <iostream>
  24.  
  25. using namespace std;
  26.  
  27. #pragma warning(disable:4996)
  28.  
  29. int n;
  30. int mat[7][7];
  31.  
  32. void pas(int i, int j);
  33.  
  34. void back(int i, int j) {
  35.     if (i == n + 1 && j == 1) {
  36.         for (int i = 1; i <= n; i++) {
  37.             for (int j = 1; j <= n; j++) {
  38.                 cout << mat[i][j] << " ";
  39.             }
  40.             cout << '\n';
  41.         }
  42.         cout << '\n';
  43.         return;
  44.     }
  45.  
  46.     if (i == j) {
  47.         mat[i][j] = 0;
  48.         pas(i, j);
  49.     }
  50.     else if (i > j) {
  51.         pas(i, j);
  52.     }
  53.     else {
  54.         mat[i][j] = 0;
  55.         mat[j][i] = 0;
  56.         pas(i, j);
  57.  
  58.         mat[i][j] = 1;
  59.         mat[j][i] = 1;
  60.         pas(i, j);
  61.     }
  62.  
  63. }
  64.  
  65. void pas(int i, int j) {
  66.     if (j == n) {
  67.         back(i + 1, 1); //rand nou
  68.     }
  69.     else {
  70.         back(i, j + 1); //continuam randul
  71.     }
  72. }
  73.  
  74. int main() {
  75.  
  76.     //freopen("input", "r", stdin);freopen("output", "w", stdout);
  77.     freopen("gengraf.in", "r", stdin);freopen("gengraf.out", "w", stdout);
  78.  
  79.     cin >> n;
  80.  
  81.     int put = n * (n - 1) / 2;
  82.     int ans = 1;
  83.  
  84.     //for (int i = 1; i <= put; i++) ans *= 2;
  85.     //while (put--) ans *= 2;
  86.     ans = (1 << put);
  87.  
  88.     cout << ans << '\n';
  89.  
  90.     for (int i = 1; i <= n; i++) {
  91.         for (int j = 1; j <= n; j++) {
  92.             mat[i][j] = -1;
  93.         }
  94.     }
  95.  
  96.     back(1, 1);
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement