찌로그
[BOJ] 백준 17825번 주사위 윷놀이 2020_05_21 C++ 본문
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 <int, int> 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 == 0) return 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==0) return {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>=21) return {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 == 0) continue; 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 |
'Coding' 카테고리의 다른 글
[BOJ] 백준 15683번 감시 2020_05_26 C++ (0) | 2020.05.26 |
---|---|
[BOJ] 백준 14891번 톱니바퀴 2020_05_22 C++ (0) | 2020.05.22 |
[BOJ] 백준 14890번 경사로 2020_05_22 C++ (0) | 2020.05.22 |
[BOJ] 백준 17822번 문제 원판 돌리기 2020_05_19 C++ (0) | 2020.05.19 |
[BOJ] 백준 15684번 문제 사다리 조작 2020_05_19 C++ (0) | 2020.05.19 |
Comments