File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+
7+ static int n, x, y, count;
8+ static int [] arr;
9+ static boolean [] used;
10+
11+ public static void main (String [] args ) throws IOException {
12+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
13+ StringTokenizer st = new StringTokenizer (br. readLine());
14+
15+ n = Integer . parseInt(st. nextToken());
16+ x = Integer . parseInt(st. nextToken());
17+ y = Integer . parseInt(st. nextToken());
18+
19+ arr = new int [2 * n + 1 ];
20+ used = new boolean [n + 1 ];
21+
22+ int fixedNum = y - x - 1 ;
23+ arr[x] = arr[y] = fixedNum;
24+ used[fixedNum] = true ;
25+
26+ check(1 );
27+
28+ System . out. println(count);
29+ }
30+
31+ static void check (int pos ) {
32+ if (pos == 2 * n + 1 ) {
33+ count++ ;
34+ return ;
35+ }
36+
37+ if (arr[pos] != 0 ) {
38+ check(pos + 1 );
39+ return ;
40+ }
41+
42+ for (int i = 1 ; i <= n; i++ ) {
43+ if (used[i]) continue ;
44+
45+ if (pos + i + 1 <= 2 * n && arr[pos + i + 1 ] == 0 ) {
46+ arr[pos] = arr[pos + i + 1 ] = i;
47+ used[i] = true ;
48+
49+ check(pos + 1 );
50+
51+ arr[pos] = arr[pos + i + 1 ] = 0 ;
52+ used[i] = false ;
53+ }
54+ }
55+ }
56+ }
57+ ```
You can’t perform that action at this time.
0 commit comments