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

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

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

인기 글

태그

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

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShovelingLife

A Game Programmer

카테고리 없음

[골4] 17404 - RGB거리 2

2023. 10. 30. 14:13
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>

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 1001

int main()
{
	FAST_IO();

	int color[MAX][3], dp[MAX][3];
	int n, ans = INT_MAX;

	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> color[i][0] >> color[i][1] >> color[i][2];

	// 1번 집의 색
	for (int rgb = 0; rgb < 3; rgb++)
	{
		// 다른 집의 색은 MAX로 지정하여 dp할때 선택되지 않도록 함
		for (int i = 0; i < 3; i++)
			dp[1][i] = (i == rgb) ? color[1][i] : 1e9;

		// DP
		for (int i = 2; i <= n; i++)
		{
			dp[i][0] = color[i][0] + min(dp[i - 1][1], dp[i - 1][2]);
			dp[i][1] = color[i][1] + min(dp[i - 1][0], dp[i - 1][2]);
			dp[i][2] = color[i][2] + min(dp[i - 1][0], dp[i - 1][1]);
		}

		// 1번집 색과 N번집 색이 겹치지 않게 함
		for (int i = 0; i < 3; i++)
		{
			if (i != rgb)
				ans = min(ans, dp[n][i]);
		}
	}
	cout << ans;
	return 0;
}
저작자표시 (새창열림)
    ShovelingLife
    ShovelingLife
    Main skill stack => Unity C# / Unreal C++ Studying Front / BackEnd, Java Python

    티스토리툴바