giabinh

XauABC

Jul 30th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int n, maxC, countC;
  6. char a[102];
  7.  
  8. bool check(int n) {
  9.     for (int len=2; len<=n/2; ++len)
  10.         for (int j=n-1; j>=n-len; --j)
  11.             if (a[j]!=a[j-len]) return true;
  12.     return false;
  13. }
  14.  
  15. void _try(int i) {
  16.     if (countC + (n-i)/4 > maxC) return;
  17.  
  18.     if (i > n) {
  19.         for (int j=0; i<n; ++j) printf("%d ", a[j]);
  20.         return;
  21.     }
  22.  
  23.     for (char j='A'; j<='C'; ++j) {
  24.         a[i]=j;
  25.         if (check(j)) {
  26.             countC += (j=='C');
  27.             _try(i+1);
  28.             countC -= (j=='C');
  29.         }
  30.     }
  31. }
  32.  
  33. int main() {
  34.     //freopen("xauabc.inp", "r", stdin);
  35.  
  36.     scanf("%d", &n); maxC=n/4; countC=0;
  37.  
  38.     _try[1];
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment