-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain17281_์ผ๊ตฌ.java
121 lines (113 loc) ยท 2.44 KB
/
Main17281_์ผ๊ตฌ.java
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
//BOJ:: 17281 ์ผ๊ตฌ
public class Main17281_์ผ๊ตฌ {
static int N;
static int[][] rst;
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(bf.readLine()); // ์ด๋
rst = new int[N][10];
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(bf.readLine());
for (int j = 1; j < 10; j++) {
rst[i][j] = Integer.parseInt(st.nextToken());
}
} //////// input
visit = new boolean[10];
player = new int[10];
player[4] = 1;
max = -1;
perm(1);
System.out.println(max);
}// end of main
static boolean[] visit;
static int[] player;
static int max;
public static void perm(int len) { // ์ ์ ๋ฐฐ์นํ๊ธฐ
if (len == 4) { // 4๋ฒ์งธ ํ์๋ 1๋ฒ.
perm(len + 1);
return;
}
if (len == 10) {
// ์ ํ์๋ฃ
int score = playGame();
max = max<score? score:max;
return;
}
for (int i = 2; i < 10; i++) {
if (visit[i])
continue;
player[len] = i;
visit[i] = true;
perm(len + 1);
visit[i] = false;
}
}
public static int playGame() {
int score = 0;
int out;
boolean[] roo = new boolean[4];
int hitter = 1;
for (int inning = 0; inning < N; inning++) {
out = 0;
Arrays.fill(roo, false);
while(true) {
int now = rst[inning][player[hitter]];
if(hitter==9) hitter = 1;
else hitter++;
if (now == 1) { // ์ํ
if(roo[3]) {
score++;
roo[3]=false;
}
for(int r=2;r>=1;r--) {
if(roo[r]) {
roo[r]=false;
roo[r+1]=true;
}
}
roo[1]=true;
} else if (now == 2) { // 2๋ฃจํ
if(roo[3]) {
score++;
roo[3]=false;
}
if(roo[2]) {
score++;
roo[2]=false;
}
if(roo[1]) {
roo[1]=false;
roo[3]=true;
}
roo[2]=true;
} else if (now == 3) { // 3๋ฃจํ
for(int r=1;r<=3;r++) {
if(roo[r]) {
score++;
roo[r]=false;
}
}
roo[3] = true;
} else if (now == 4) { // ํ๋ฐ
for(int r=1;r<=3;r++) {
if(roo[r]) {
score++;
roo[r]=false;
}
}
score++; //ํ์๋ ํ์ผ๋ก.
} else if (now == 0) { // ์์
out++;
if (out == 3) {
break;
}
}
}
}// end of for
return score;
} //end of playGame
}// end of class