dlstjd0117   5년 전

#include
#include
#include
#include

using namespace std;

int N;
int bfs(int count, vector> Map, int dir) {
if (count == 0) {
int max = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (Map[i][j] > max) {
max = Map[i][j];
}
}
}
return max;
}
vector> newMap = vector>(N, vector(N));
vector> checkMap = vector>(N, vector(N));
switch (dir) {
case 0: {
cout << "UP" << "\n";
vector iIndex = vector(N, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (Map[i][j] != 0) {
newMap[iIndex[j]][j] = Map[i][j];
if (iIndex[j] != 0) {
if (newMap[iIndex[j] - 1][j] == Map[i][j] && checkMap[iIndex[j] - 1][j] == 0) {
newMap[iIndex[j] - 1][j] += newMap[iIndex[j] - 1][j];
checkMap[iIndex[j] - 1][j] = 1;
newMap[iIndex[j]][j] = 0;
}
else {
iIndex[j]++;
}
}
else {
iIndex[j]++;
}
}
}
}
}
break;
case 1: {
cout << "DOWN" << "\n";
vector iIndex = vector(N, N - 1);
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j < N; j++) {
if (Map[i][j] != 0) {
newMap[iIndex[j]][j] = Map[i][j];
if (iIndex[j] != N - 1) {
if (newMap[iIndex[j] + 1][j] == Map[i][j] && checkMap[iIndex[j] + 1][j]) {
newMap[iIndex[j] + 1][j] += newMap[iIndex[j] + 1][j];
checkMap[iIndex[j] + 1][j] = 1;
newMap[iIndex[j]][j] = 0;
}
else {
iIndex[j]--;
}
}
else {
iIndex[j]--;
}
}
}
}
}
break;
case 2: {
cout << "LEFT" << "\n";
vector jIndex = vector(N, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (Map[i][j] != 0) {
newMap[i][jIndex[i]] = Map[i][j];
if (jIndex[i] != 0) {
if (newMap[i][jIndex[i] - 1] == Map[i][j] && checkMap[i][jIndex[i] - 1] == 0) {
newMap[i][jIndex[i] - 1] += newMap[i][jIndex[i] - 1];
checkMap[i][jIndex[i] - 1] = 1;
newMap[i][jIndex[i]] = 0;
}
else {
jIndex[i]++;
}
}
else {
jIndex[i]++;
}
}
}
}
}
break;
case 3: {
cout << "RIGHT" << "\n";
vector jIndex = vector(N, N - 1);
for (int i = 0; i < N; i++) {
for (int j = N - 1; j >= 0; j--) {
if (Map[i][j] != 0) {
newMap[i][jIndex[i]] = Map[i][j];
if (jIndex[i] != N - 1) {
if (newMap[i][jIndex[i] + 1] == Map[i][j] && checkMap[i][jIndex[i] + 1] == 0) {
newMap[i][jIndex[i] + 1] += newMap[i][jIndex[i] + 1];
checkMap[i][jIndex[i] + 1] = 1;
newMap[i][jIndex[i]] = 0;
}
else {
jIndex[i]--;
}
}
else {
jIndex[i]--;
}
}
}
}
}
break;
}

count--;
return max(max(max(bfs(count, newMap, 0), bfs(count, newMap, 1)), bfs(count, newMap, 2)), bfs(count, newMap, 3));
}

int main()
{
cin >> N;
vector> MAP = vector>(N, vector(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> MAP[i][j];
}
}

cout << max(max(max(bfs(5, MAP, 0), bfs(5, MAP, 1)), bfs(5, MAP, 2)), bfs(5, MAP, 3));

return 0;
}

dlstjd0117   5년 전

if (newMap[iIndex[j] + 1][j] == Map[i][j] && checkMap[iIndex[j] + 1][j])  여기에

if (newMap[iIndex[j] + 1][j] == Map[i][j] && checkMap[iIndex[j] + 1][j] == 0) 을 안붙였었네요.

댓글을 작성하려면 로그인해야 합니다.