-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17281_โพ.java
More file actions
142 lines (136 loc) ยท 3.28 KB
/
17281_โพ.java
File metadata and controls
142 lines (136 loc) ยท 3.28 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
static int N, p, Max;
static int input[][]; //์
๋ ฅ ๋งต
static int arr[] = new int[] {1,2,3,4,5,6,7,8}; //4๋ฒ์ฃผ์๋ฅผ ์ ์ธํ 8๊ฐ ๋ฒํธ์ ๋ํ ์์ด์ ์ํ ๋ฐฐ์ด
static int[] solutionArr = new int[9]; //์ฒดํฌํ ํ์๋ฒํธ ๋ฐฐ์ด
static int[] logicArr = new int[8]; //์์ด์ํ ๋ฐฐ์ด
static boolean[] visited; //์์ด ๋ฐฉ๋ฌธ์ฒดํฌ์ฉ
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine()," ");
N = Integer.parseInt(st.nextToken());
input = new int[N][9];
for(int i=0; i<N; i++) { //์
๋ ฅ
st = new StringTokenizer(br.readLine()," ");
for(int j=0; j<9; j++) {
input[i][j] = Integer.parseInt(st.nextToken());
}
}
visited = new boolean[8];
todo(0);
System.out.println(Max); //์ ๋ต ์ถ๋ ฅ
}
static void todo(int cnt) { //์์ด ๋ฉ์๋
if(cnt == 8) {
//์์ด์์ฑ ํ์ ์์ ์ ํ์.
int ct= 0;
for(int i=0; i<8; i++) { //solutionArr : ์ต์ข
ํ์์์
if(ct == 3) ct++; //4๋ฒํ์๋ ๊ณ ์ ๋์๊ธฐ ๋๋ฌธ์ ๋์ด๊ฐ
solutionArr[ct++] = logicArr[i];
}
int score = Solution(); //๋ก์ง
Max = Math.max(Max, score);
} else {
for(int i=0; i<8; i++) {
if(!visited[i]) {
logicArr[cnt] = arr[i];
visited[i] = true;
todo(cnt + 1);
visited[i] = false;
}
}
}
}
private static int Solution() {
int base[] = new int[4]; //1~3๋ฃจ ๊ด๋ฆฌ๋ฅผ ์ํ ๋ฐฐ์ด
int score = 0; //ํ์ฌ ํ์์์ด์ ๋ํ ์ ์๊ฐ
int batter = 0; //ํ์ฌ ํ์๋ฒํธ
for(int i=0; i<N; i++) { //์ด๋
int out = 0; //out์นด์ดํธ
int Next = 0; //3out ์ฒดํฌ์ฉ
while(true) { //ํ์ ์งํ
int bat = batter % 9;
int idx = input[i][solutionArr[bat]]; //๋ญ ์ณค๋์ง
batter += 1;
switch(idx) { //๋ค์ด์จ ์
๋ ฅ์ ๋ฐ๋ฅธ ํ๋
case 0: //out
out++;
if(out == 3) {
Next = 1; //ํ์ถ์ฉ ์ฒดํฌ
for(int k=1; k<4; k++) { //์ด๊ธฐํ
base[k] = 0;
}
break;
}
break;
case 1: //1๋ฃจํ
if(base[3] == 1) {
score++;
base[3] = 0;
}
if(base[2] == 1) {
base[3] = 1;
base[2] = 0;
}
if(base[1] == 1) {
base[2] = 1;
base[1] = 0;
}
base[1] = 1;
break;
case 2: //2๋ฃจํ
if(base[3] == 1) {
score++;
base[3] = 0;
}
if(base[2] == 1) {
score++;
base[2] = 0;
}
if(base[1] == 1) {
base[3] = 1;
base[1] = 0;
}
base[2] = 1;
break;
case 3: //3๋ฃจํ
if(base[3] == 1) {
score++;
base[3] = 0;
}
if(base[2] == 1) {
score++;
base[2] = 0;
}
if(base[1] == 1) {
score++;
base[1] = 0;
}
base[3] = 1;
break;
case 4: //ํ๋ฐ
for(int k=1; k<4; k++) {
if(base[k] == 1) {
score++;
base[k] = 0;
}
}
score++;
break;
}
if(Next == 1) {
Next = 0;
break;
}
}
}
return score; //๊ฒฐ๊ณผ ๋ฆฌํด
}
}