Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- C
- winapi
- 오블완
- 티스토리챌린지
- softeer
- 1563
- 백준
- 2294
- Programmers
- 언리얼엔진5
- RootMotion
- DirectX11
- UnrealEngine5
- 팰린드롬 만들기
- directx
- Frustum
- UnrealEngine4
- Unreal Engine5
- RVO
- 줄 세우기
- TObjectPtr
- IFileDialog
- UE5
- baekjoon
- algorithm
- GeeksForGeeks
- NRVO
- 프로그래머스
- const
- C++
Archives
- Today
- Total
Game Develop
[Algorithm] Baekjoon 2661번 : 좋은수열 본문
https://www.acmicpc.net/problem/2661
2661번: 좋은수열
첫 번째 줄에 1, 2, 3으로만 이루어져 있는 길이가 N인 좋은 수열들 중에서 가장 작은 수를 나타내는 수열만 출력한다. 수열을 이루는 1, 2, 3들 사이에는 빈칸을 두지 않는다.
www.acmicpc.net
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
int targetCount = 0;
string result = "";
bool isCheck = false;
bool check(string s)
{
for (int i = 1; i <= s.size() / 2; i++)
{
string left = s.substr(s.size() - i * 2, i);
string right = s.substr(s.size() - i, i);
if (left == right) return false;
}
return true;
}
void DFS(string s, int count)
{
if (s.size() == targetCount)
{
isCheck = true;
result = s;
return;
}
for (int i = 1; i <= 3; i++)
{
string temp = s;
temp += i + '0';
if (check(temp))
{
DFS(temp, count + 1);
}
if (isCheck) return;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n = 0;
cin >> n;
targetCount = n;
DFS("", 0);
cout << result << endl;
}
|
cs |
숫자하나씩 추가할때마다 뒤에서부터 s.size() / 2까지 구간별 검사를 해서 한번이라도 일치하면 false를 리턴한다.
규칙찾는게 어렵긴한데, 어떻게든 찾으면 구현은 이제 무난하게 하는것같다.
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm] Baekjoon 10971번 : 외판원 순회 2 (1) | 2022.10.14 |
---|---|
[Algorithm] Baekjoon 9663번 : N-Queen (0) | 2022.10.14 |
[Algorithm] Baekjoon 2580번 : 스도쿠 (1) | 2022.10.13 |
[Algorithm] Baekjoon 1405번 : 미친 로봇 (0) | 2022.10.13 |
[Algorithm] Baekjoon 1339번 : 단어 수학 (0) | 2022.10.13 |