Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 268a95f

Browse files
committed
고다혜: [CT] 윷놀이 사기단_241216
1 parent 9936cb5 commit 268a95f

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class DH_윷놀이_사기단 {
5+
static final int TURN = 10;
6+
static int[] arr, sel; // 중복 순열
7+
static int[][] map;
8+
static class Horse {
9+
int r, c;
10+
public Horse() {}
11+
@Override
12+
public String toString() {
13+
return "Horse [r=" + r + ", c=" + c + "]";
14+
}
15+
}
16+
static int maxResult;
17+
static boolean[] v;
18+
static Horse[] horses;
19+
20+
public static void main(String[] args) throws Exception {
21+
horses = new Horse[5];
22+
v = new boolean[5];
23+
for(int i = 0; i < horses.length; i++) horses[i] = new Horse();
24+
25+
map = new int[][]{
26+
{0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 41},
27+
{10, 13, 16, 19, 25, 30, 35, 40, 41},
28+
{20, 22, 24, 25, 30, 35, 40, 41},
29+
{30, 28, 27, 26, 25, 30, 35, 40, 41}};
30+
31+
initInput();
32+
solution();
33+
System.out.println(maxResult);
34+
}
35+
36+
37+
static void solution() {
38+
sel = new int[10];
39+
func(0, 0);
40+
}
41+
42+
static void func(int depth, int result) {
43+
if(depth == TURN) {
44+
maxResult = Math.max(maxResult, result);
45+
return;
46+
}
47+
48+
for(int i = 1; i < 5; i++) {
49+
if(v[i]) continue;
50+
sel[depth] = i;
51+
52+
int currentR = horses[i].r;
53+
int currentC = horses[i].c;
54+
55+
int nr = currentR;
56+
int nc = currentC + arr[depth];
57+
58+
if(nc >= map[nr].length) {
59+
nc = map[nr].length - 1;
60+
v[i] = true;
61+
} else {
62+
if(map[nr][nc] == 10 || map[nr][nc] == 20 ||
63+
(map[nr][nc] == 30 && map[nr][nc - 1] == 28)) {
64+
nr = map[nr][nc] / 10;
65+
nc = 0;
66+
}
67+
68+
boolean canGo = true;
69+
70+
for(int j = 1; j < 5; j++) {
71+
if(j == i) continue;
72+
if(map[horses[i].r][horses[i].c] == 0 || map[horses[j].r][horses[j].c] == 0) continue;
73+
if(map[horses[i].r][horses[i].c] == 41 || map[horses[j].r][horses[j].c] == 41) continue;
74+
75+
if(nr == horses[j].r && nc == horses[j].c) {
76+
canGo = false;
77+
break;
78+
}
79+
}
80+
81+
if(!canGo) continue;
82+
}
83+
84+
horses[i].r = nr;
85+
horses[i].c = nc;
86+
87+
func(depth + 1, result + (map[nr][nc] % 41));
88+
89+
horses[i].r = currentR;
90+
horses[i].c = currentC;
91+
92+
if(currentC < map[currentR].length) {
93+
v[i] = false;
94+
}
95+
}
96+
}
97+
98+
static void initInput() throws Exception {
99+
System.setIn(new FileInputStream("./input/윶놀이사기단.txt"));
100+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
101+
StringTokenizer st = new StringTokenizer(br.readLine());
102+
103+
arr = new int[10];
104+
for(int i = 0; i < 10; i++) arr[i] = Integer.parseInt(st.nextToken());
105+
}
106+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /