Skip to content

Commit d01a55b

Browse files
committed
[Gold V] Title: 랭퍼든 수열쟁이야!!, Time: 116 ms, Memory: 2020 KB -BaekjoonHub
1 parent 5957f75 commit d01a55b

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# [Gold V] 랭퍼든 수열쟁이야!! - 15918
2+
3+
[문제 링크](https://www.acmicpc.net/problem/15918)
4+
5+
### 성능 요약
6+
7+
메모리: 2020 KB, 시간: 116 ms
8+
9+
### 분류
10+
11+
백트래킹
12+
13+
### 제출 일자
14+
15+
2026년 3월 2일 14:29:06
16+
17+
### 문제 설명
18+
19+
<p>랭퍼드 수열은 다음 조건을 만족하는 길이 2n의 수열이다.</p>
20+
21+
<ol>
22+
<li>1 이상 n 이하의 자연수가 각각 두 개씩 들어 있다.</li>
23+
<li>두 개의 1 사이에는 정확히 1개의 수가 있다.</li>
24+
<li>두 개의 2 사이에는 정확히 2개의 수가 있다.</li>
25+
<li>...</li>
26+
<li>두 개의 n 사이에는 정확히 n개의 수가 있다.</li>
27+
</ol>
28+
29+
<p>예를 들어 3, 1, 2, 1, 3, 2은 n=3인 랭퍼드 수열이다.</p>
30+
31+
<p>n이 주어졌을 때, 길이 2n의 랭퍼드 수열의 개수를 구하면 된다. 하지만 이렇게만 하면 재미가 없으니 조건 하나를 추가하고자 한다. x번째 수와 y번째 수는 같다는 조건이다. (이 번호는 1부터 시작한다.)</p>
32+
33+
### 입력
34+
35+
<p>세 자연수 n, x, y가 주어진다. (2 ≤ n ≤ 12, 1 ≤ x < y ≤ 2n, 1 ≤ y-x-1 ≤ n)</p>
36+
37+
### 출력
38+
39+
<p>x번째 수와 y번째 수가 같은 길이 2n의 랭퍼드 수열의 개수를 출력한다.</p>
40+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
const int N = 13;
5+
int n, x, y, uc, ans;
6+
bool used[ N ];
7+
int arr[ N * 2 ];
8+
9+
void bt( int level )
10+
{
11+
if ( level > 2 * n )
12+
return;
13+
14+
for ( int i = 1; i <= n; ++i )
15+
{
16+
if ( used[ i ] )
17+
continue;
18+
19+
if ( level + i + 1 > 2 * n )
20+
continue;
21+
22+
if ( arr[ level + i + 1 ] )
23+
continue;
24+
25+
used[ i ] = true;
26+
arr[ level ] = i;
27+
arr[ level + i + 1 ] = i;
28+
++uc;
29+
if ( uc != n )
30+
{
31+
for ( int j = level + 1; j <= 2 * n; ++j )
32+
{
33+
if ( !arr[ j ] )
34+
{
35+
bt( j );
36+
break;
37+
}
38+
}
39+
}
40+
else ++ans;
41+
--uc;
42+
arr[ level + i + 1 ] = 0;
43+
arr[ level ] = 0;
44+
used[ i ] = false;
45+
}
46+
}
47+
48+
int main()
49+
{
50+
cin >> n >> x >> y;
51+
52+
int diff = y - x - 1;
53+
used[ diff ] = true;
54+
arr[ x ] = diff;
55+
arr[ y ] = diff;
56+
++uc;
57+
58+
bt( x == 1 ? 2 : 1 );
59+
cout << ans;
60+
}

0 commit comments

Comments
 (0)