ShovelingLife
A Game Programmer
ShovelingLife
전체 방문자
오늘
어제
  • 분류 전체보기 (1089) N
    • 그래픽스 (57)
      • 공통 (19)
      • 수학 물리 (22)
      • OpenGL & Vulkan (1)
      • DirectX (14)
    • 게임엔진 (184)
      • Unreal (69)
      • Unity (104)
      • Cocos2D-X (3)
      • 개인 플젝 (8)
    • 코딩테스트 (221)
      • 공통 (7)
      • 프로그래머스 (22)
      • 백준 (162)
      • LeetCode (19)
      • HackerRank (2)
      • 코딩테스트 알고리즘 (8)
    • CS (240)
      • 공통 (21)
      • 네트워크 (44)
      • OS & 하드웨어 (60)
      • 자료구조 & 알고리즘 (98)
      • 디자인패턴 (6)
      • UML (4)
      • 데이터베이스 (7)
    • 프로그래밍 언어 (358) N
      • C++ (168)
      • C# (93) N
      • Java (11)
      • Python (35)
      • SQL (30)
      • JavaScript (9)
      • React (7)
    • 그 외 (20)
      • Math (5)
      • 일상 (5)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • Source Code 좌측 상단에 복사 버튼 추가 완료
  • 언리얼 엔진 C++ 빌드시간 단축 꿀팁
  • 게임 업계 코딩테스트 관련
  • 1인칭 시점으로 써내려가는 글들

인기 글

태그

  • 오블완
  • 배열
  • C++
  • 백준
  • 문자열
  • SQL
  • 티스토리챌린지
  • 알고리즘
  • python
  • string
  • 포인터
  • 유니티
  • 언리얼
  • 파이썬
  • c#
  • Unity
  • 그래픽스
  • C
  • 함수
  • 클래스

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShovelingLife

A Game Programmer

코딩테스트/백준

[골4] 14500 - 테트로미노

2023. 11. 21. 22:12
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <queue>	

using namespace std;
using ll = long long;

#pragma region 상하좌우 / 위치

const pair<int, int> dir[]
{
	{  1,  0 },
	{ -1,  0 },
	{  0, -1 },
	{  0,  1 },
};

#define _y first
#define _x second

#pragma endregion

#pragma region 빠른 입출력

#define FAST_IO() \
{\
	ios::sync_with_stdio(false);\
	cin.tie(NULL); \
	cout.tie(NULL); \
}\

#pragma endregion

#define MAX 501

vector<vector<bool>> vis;
vector<vector<int>> map;
int n, m, res;

void DFS(int y, int x, int cnt, int sum)
{
	if (cnt == 4)
	{
		res = max(res, sum);
		return;
	}
	for (int i = 0; i < 4; i++)
	{
		int ny = y + dir[i]._y, nx = x + dir[i]._x;

		if (nx < 0  ||
			ny < 0  ||
			nx >= m ||
			ny >= n)
			continue;

		if (vis[ny][nx])
			continue;

		vis[ny][nx] = true;		
		DFS(ny, nx, cnt + 1, sum + map[ny][nx]);
		DFS(y, x,	cnt + 1, sum + map[ny][nx]);
		vis[ny][nx] = false;
	}
}

int main()
{
	FAST_IO();

	cin >> n >> m;
	map.resize(n, vector<int>(m));
	vis.resize(n, vector<bool>(m));

	for (int y = 0; y < n; y++)
	{
		for (int x = 0; x < m; x++)
			cin >> map[y][x];
	}
	for (int y = 0; y < n; y++)
	{
		for (int x = 0; x < m; x++)
		{
			vis[y][x] = true;
			DFS(y, x, 1, map[y][x]);
			vis[y][x] = false;
		}
	}
	cout << res;
}

 

 

참고

[Algorithm] 백준 14500 테트로미노 - C++, DFS :: 껍데기방 (tistory.com)

저작자표시 (새창열림)

'코딩테스트 > 백준' 카테고리의 다른 글

파이썬 1157 - 단어 공부  (0) 2023.12.19
[실1] 3019 - 테트리스  (0) 2023.11.22
[골3] 7579 - 앱  (0) 2023.10.30
[골4] 20040 - 사이클 게임  (0) 2023.10.30
[골4] 1405 - 미친 로봇  (0) 2023.10.26
    '코딩테스트/백준' 카테고리의 다른 글
    • 파이썬 1157 - 단어 공부
    • [실1] 3019 - 테트리스
    • [골3] 7579 - 앱
    • [골4] 20040 - 사이클 게임
    ShovelingLife
    ShovelingLife
    Main skill stack => Unity C# / Unreal C++ Studying Front / BackEnd, Java Python

    티스토리툴바