Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
more
Archives
Today
Total
관리 메뉴

찌로그

[BOJ] 백준 17825번 주사위 윷놀이 2020_05_21 C++ 본문

Coding

[BOJ] 백준 17825번 주사위 윷놀이 2020_05_21 C++

찌드 2020. 5. 21. 22:17

https://www.acmicpc.net/problem/17825

 

17825번: 주사위 윷놀이

주사위 윷놀이는 다음과 같은 게임판에서 하는 게임이다. 처음에는 시작 칸에 말 4개가 있다. 말은 게임판에 그려진 화살표의 방향대로만 이동할 수 있다. 말이 파란색 칸에서 이동을 시작하면 �

www.acmicpc.net

 

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
#include <bits/stdc++.h>
using namespace std;
typedef pair <intint> p;
int inp[10], answer = INT_MIN;
 
int maps[6][22]={
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,-1},
    {10,13,16,19,25,30,35,40,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {20,22,24,25,30,35,40,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {30,28,27,26,25,30,35,40,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
    {25,30,35,40,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}};
 
bool onChk(p x, vector<p> h){ // return true if exist >> can't go
    int a = x.first, b = x.second;
    if(a == 0return false;
    for(int i=0; i<4; i++){
        p t = h[i];
        if(t.first == a && t.second == b) return true;
    }
    return false;
}
p mov(int x, int y){
    if(x==0return {0,0};
    if(x ==1 && y % 5 == 0){
        if(y/5 <=3){
            x += y / 5;
            y=0;
        }else return {5,3};
    }else if(x ==1 && y>=21return {0,0};
 
    if( ( x==2 || x== 4 ) && y>=4 ){x= 5; y = y-4;}
    else if(x==3 && y>=3 ){x= 5;y= y-3;}
 
    if(maps[x][y] == -1 ) return {0,0};
 
    return {x,y};
}
void dfs(int idx, int val, vector<p> h){
    if(idx > 9){
        answer = max(answer, val);
        return;
    }
    for(int i=0; i<4; i++){
        vector<p> nh(4);
        nh.assign(h.begin(), h.end());
        p x = nh[i];
        if(x.first == 0continue;
        p t= mov(x.first, x.second+ inp[idx]);
 
        if(!onChk(t,nh)){
            nh[i] = t;
            dfs(idx+1, val + maps[t.first][t.second], nh);
        }
        else continue;
 
    }
 
}
int main(){
    for(int i=0; i<10; i++cin >> inp[i];
 
    vector<p> horse(4, {1,0});
    dfs(0,0, horse);
    cout << answer <<endl;
 
    return 0;
}
 
 
cs
Comments