Iamtui1010

daycon

Nov 18th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<fstream>
  3. #include<vector>
  4. #include<iostream>
  5.  
  6. #define long long long
  7. #define nln '\n'
  8.  
  9. using namespace std;
  10.  
  11. // Global variables: f1, f2, n, m
  12.  
  13. fstream f1, f2;
  14.  
  15. inline void openf()
  16. {
  17.     f1.open("daycon.inp", ios:: in);
  18.     f2.open("daycon.out", ios:: out);
  19. }
  20.  
  21. inline void closef()
  22. {
  23.     f1.close();
  24.     f2.close();
  25. }
  26.  
  27. long n, m;
  28. vector<long> a;
  29.  
  30. void data()
  31. {
  32.     f1.tie(0)->sync_with_stdio(0);
  33.     f2.tie(0)->sync_with_stdio(0);
  34.     f1 >> n >> m;
  35. }
  36.  
  37. bool check(long loc)
  38. {
  39.     long dis = loc / 2;
  40.     for (long i = 1; i <= dis; ++i)
  41.     {
  42.         bool sam = 1;
  43.         for (long j = loc - i*2 + 1; j <= loc-i; ++j)
  44.             if (a[j] != a[j+i])
  45.             {
  46.                 sam = 0;
  47.                 break;
  48.             }
  49.         if (sam)
  50.             return 0;
  51.     }
  52.     return 1;
  53. }
  54.  
  55. long cou = 0;
  56.  
  57. void recursion(long i)
  58. {
  59.     if (i > n)
  60.     {
  61.         ++cou;
  62.         f2 << cou << " : ";
  63.         for (long j = 1; j <= n; ++j)
  64.             f2 << a[j];
  65.         f2 << nln;
  66.         return;
  67.     }
  68.     for (long j = 1; j <= m; ++j)
  69.     {
  70.         a[i] = j;
  71.         if (check(i))
  72.             recursion(i+1);
  73.     }
  74. }
  75.  
  76. void process()
  77. {
  78.     a.resize(n+1, 0);
  79.     recursion(1);
  80. }
  81.  
  82. void view()
  83. {
  84. }
  85.  
  86. int main()
  87. {
  88.     openf();
  89.     data();
  90.     process();
  91.     view();
  92.     closef();
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment