1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| #include <stdio.h>#include <string.h>#include <stdlib.h>int n;char a[99];int isValid(int here){ int i,len; for(len = 1; len <= (here+1)/2; len++) for(i = 0 ; i <= here + 1 - 2*len ; i++) // start pos of left str if(strncmp(a+i, a+len+i ,len) == 0) return 0; return 1;}void go(int here){ int i; if(here == n) { a[here] = '\0'; puts(a); exit(0); } for(i = 1; i <= 3 ;i++) { a[here] = i+ '0'; if(isValid(here)) go(here + 1); }}int main(){ scanf("%d",&n); go(0); return 0;}
isValid() 에서 index체크를 신경써서 해야한다.
|