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
- 시뮬레이션
- math
- 투포인터
- 코테
- 프로그래머스
- priorityqueue
- 코딩테스트
- 문제풀이
- SWEA
- 건강
- 문제해결
- DP
- BOJ
- 알고리즘
- 운동기록
- db
- dfs
- greedy
- binary search
- 백준
- oracle
- COS PRO
- 이분탐색
- 러닝일지
- 자바
- BFS
- SQL
- MySQL
- Java
- 문자열
Archives
- Today
- Total
슈콩
[BOJ] 17825 주사위 윷놀이 본문


[문제]
https://www.acmicpc.net/problem/17825
[소스 코드]
import java.io.*;
import java.util.*;
public class Main {
static int[] board = {
0,2,4,6,8,10,12,14,16,18,20,
22,24,26,28,30,32,34,36,38,40,
13,16,19,22,24,28,27,26,25,30,
35,0
};
static int[] dices,locs,spacial,nxt;
static int result = 0;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
dices = new int[10];
for(int i=0;i<10;i++) {
dices[i] = Integer.parseInt(st.nextToken());
}
locs = new int[4];
spacial = new int[33];
nxt = new int[33];
for(int i=0;i<32;i++) nxt[i] = i+1;
nxt[23] = nxt[25] = 29;
nxt[31] = 20;
nxt[20] = 32;
spacial[5] = 21;
spacial[10] = 24;
spacial[15] = 26;
dfs(0,0);
System.out.println(result);
}
private static void dfs(int idx,int sum) {
if(idx==10) {
result = Math.max(result, sum);
return;
}
int dice = dices[idx];
for(int i=0;i<4;i++) {
int loc = locs[i];
if(loc==32) continue;
int tempLoc = loc;
for(int j=0;j<dice;j++) {
if(tempLoc==32) break;
if(j==0 && spacial[tempLoc]!=0) tempLoc = spacial[tempLoc];
else tempLoc = nxt[tempLoc];
}
boolean collision = false;
if(tempLoc!=32) {
for(int j=0;j<4;j++) {
if(i!=j && locs[j]==tempLoc) {
collision = true;
break;
}
}
}
if(!collision) {
locs[i] = tempLoc;
dfs(idx+1,sum+board[tempLoc]);
locs[i] = loc;
}
}
}
}'Algorithms > Baekjoon' 카테고리의 다른 글
| [BOJ] 1260 DFS와 BFS (3) | 2026.01.08 |
|---|---|
| [BOJ] 19236 청소년 상어 (0) | 2025.12.17 |
| [BOJ] 17822 원판돌리기 (0) | 2025.12.12 |
| [BOJ] 17837 새로운 게임 2 (0) | 2025.12.09 |
| [BOJ] 17779 게리멘더링 2 (0) | 2025.12.08 |