Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 문자열
- 알고리즘
- SWEA
- dfs
- math
- 코테
- MySQL
- BFS
- greedy
- 문제풀이
- 백준
- 프로그래머스
- 러닝일지
- Java
- 코딩테스트
- binary search
- 건강
- 운동기록
- 시뮬레이션
- db
- 이분탐색
- 투포인터
- DP
- SQL
- 자바
- BOJ
- COS PRO
- 문제해결
- oracle
- priorityqueue
Archives
- Today
- Total
슈콩
[BOJ] 백준 17281 ⚾ 본문
[문제]
https://www.acmicpc.net/problem/17281
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int n,result = Integer.MIN_VALUE;
static int[][] inning;
static boolean[] visit;
static int[] order;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
n = Integer.parseInt(br.readLine());
inning = new int[n][9];
visit = new boolean[9];
order = new int[9];
order[3] = 0;
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<9;j++) {
inning[i][j] = Integer.parseInt(st.nextToken());
}
}
perm(0);
System.out.println(result);
}
private static void perm(int cnt) {
if(cnt==9) {
game();
return;
}
for(int i=1;i<9;i++) {
if(!visit[i]) {
visit[i] = true;
order[cnt] = i;
if(cnt==2) perm(4);
else perm(cnt+1);
visit[i] = false;
}
}
}
private static void game() {
int idx = 0;
int score = 0;
for(int t=0;t<n;t++) {
int[] base = new int[4];
int cnt = 0;
while(cnt<3) {
int res = inning[t][order[idx]];
if(res==0) {
cnt++;
}
else if(res==1) {
score += base[3];
base[3] = base[2];
base[2] = base[1];
base[1] = 1;
}
else if(res==2) {
score += base[3] + base[2];
base[3] = base[1];
base[2] = 1;
base[1] = 0;
}
else if(res==3) {
score += base[3] + base[2] + base[1];
base[3] = 1;
base[2] = base[1] = 0;
}
else {
score += base[3] + base[2] + base[1] + 1;
base[3] = base[2] = base[1] = 0;
}
idx = (idx+1) % 9;
}
}
result = Math.max(result, score);
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 백준 1260 DFS와 BFS (0) | 2025.09.29 |
|---|---|
| [BOJ] 백준 23289 온풍기 안녕! (2) | 2025.09.27 |
| [BOJ] 백준 17144 미세먼지 안녕! (2) | 2025.09.26 |
| [BOJ] 백준 17143 낚시왕 (2) | 2025.09.25 |
| [BOJ] 백준 17142 연구소 3 (0) | 2025.09.25 |