반응형
https://www.acmicpc.net/problem/17825
17825번: 주사위 윷놀이
첫째 줄에 주사위에서 나올 수 10개가 순서대로 주어진다.
www.acmicpc.net
#include <bits/stdc++.h>
using namespace std;
int dice[11];
int nextPosition[33] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,32,22,23,29,25,29,27,28,29,30,31,20,32};
int point[33] = {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};
int horsePosition[4];
int ans = 0;
int horseMove(int x, int cnt){
//already arrive
if(x==32) return -1;
//nx : other horse
//blue move
if(x==5){
x = 21;
cnt--;
}
else if(x==10){
x = 24;
cnt--;
}
else if(x==15){
x = 26;
cnt--;
}
//이동
for(int i=0; i<cnt; i++){
x = nextPosition[x];
}
//other horse
for(int i=0; i<4; i++){
if(x!=32 && horsePosition[i] == x){
return -1;
}
}
return x;
}
void backTrack(int L, int curPoint) {
if (L == 10) {
ans = max(ans, curPoint);
return;
}
for (int i = 0; i < 4; i++) {
int x = horsePosition[i];
int nx = horseMove(horsePosition[i], dice[L]);
if (nx < 0) continue;
horsePosition[i] = nx;
backTrack(L + 1, point[nx] + curPoint);
horsePosition[i] = x;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for(int i=0; i<10; i++){
cin >> dice[i];
}
backTrack(0, 0);
cout << ans << '\n';
}
반응형
'Algorithm > problem' 카테고리의 다른 글
백준 19236번 : 청소년 상어 - 백트래킹 Cpp (0) | 2022.07.18 |
---|---|
백준 20061번 : 모노미노도미노2 - 구현, 시뮬레이션 C++ (0) | 2022.07.15 |
백준 17822번 : 원판 돌리기 - 구현, 시뮬레이션 C++ (0) | 2022.07.13 |
백준 17837번 : 새로운 게임 2 - 시뮬레이션 Cpp (0) | 2022.07.12 |
백준 17779번 : 게리맨더링 2 - brute Force cpp (0) | 2022.07.10 |