728x90
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<deque>
#include<math.h>
#include<cmath>
#include<unordered_map>
using namespace std;
//lookup table 만들기
// 점수, 1칸움직였을때, 2칸 '', .....
const int board[33][6] ={
{ 0,1,2,3,4,5 },
{ 2,2,3,4,5,6 },
{ 4,3,4,5,6,7 },
{ 6,4,5,6,7,8 },
{ 8,5,6,7,8,9 },
{ 10,21,22,23,24,25 },
{ 12,7,8,9,10,11 },
{ 14,8,9,10,11,12 },
{ 16,9,10,11,12,13 },
{ 18,10,11,12,13,14 },
{ 20,27,28,24,25,26 },
{ 22,12,13,14,15,16 },
{ 24,13,14,15,16,17 },
{ 26,14,15,16,17,18 },
{ 28,15,16,17,18,19 },
{ 30,29,30,31,24,25 },
{ 32,17,18,19,20,32 },
{ 34,18,19,20,32,32 },
{ 36,19,20,32,32,32 },
{ 38,20,32,32,32,32 },
{ 40,32,32,32,32,32 },
{ 13,22,23,24,25,26 },
{ 16,23,24,25,26,20 },
{ 19,24,25,26,20,32 },
{ 25,25,26,20,32,32 },
{ 30,26,20,32,32,32 },
{ 35,20,32,32,32,32 },
{ 22,28,24,25,26,20 },
{ 24,24,25,26,20,32 },
{ 28,30,31,24,25,26 },
{ 27,31,24,25,26,20 },
{ 26,24,25,26,20,32 },
{ 0,32,32,32,32,32 }
};
int dice[10];
int get_score(int state) {
int ret = 0;
bool visited[33] = { false, };
int pos[4] = { 0, };
for (int i = 0; i < 10; ++i) {
int move = dice[i];
int horse = (state >> (i * 2)) & 0x03;
int& cur_pos = pos[horse]; //& 안붙이면 답이 안나옴...
int next_pos = board[cur_pos][move];
int add_score = board[next_pos][0];
if (visited[next_pos] && next_pos != 32) {
return -1;
}
ret += add_score;
visited[cur_pos] = false;
visited[next_pos] = true;
cur_pos = next_pos;
}
return ret;
}
int main() {
for (int i = 0; i < 10; ++i) {
cin >> dice[i];
}
int result = 0;
for (int state = 0; state < (1 << 20); ++state) {
int candi = get_score(state);
if (result < candi) {
result = candi;
}
}
cout << result<<endl;
}
'백준 > 삼성기출' 카테고리의 다른 글
어른상어/ 시뮬레이션 (0) | 2021.04.12 |
---|---|
청소년 상어/ 백트래킹 (0) | 2021.04.12 |
게리맨더링2/ 구현 (0) | 2021.04.08 |
사다리조작 / 브루트포스 (0) | 2021.04.05 |
감시/JAVA (0) | 2021.04.05 |