Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ASTAR
- Unity
- Hp바
- Ainimation Blending
- 플레이어 이동
- C#
- Blend Type
- LayerMark
- Hpbar
- CSharp #자료구조
- 충돌위험 찾기
- heap tree
- 너비 우선 탐색
- 오브젝트 풀링
- 깊이 우선 탐색
- Scrooling
- Object Poling
- Lv2
- Algorithm
- pccp 기출문제 2번
- raycasting
- 유니티
- 플레이어 방향전환
- Object Pooling
- 2D슈팅게임
- Back Tracking
- pccp 기출문제 1번
- pccp 기출문제 3번
- 프로그래머스
- Animation State Machine
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.2 피로도 본문
https://school.programmers.co.kr/learn/courses/30/lessons/87946
1. 정답코드 및 핵심 아이디어, 유의사항
조건에 따라 현재 피로도로 가장 많은 던전을 구하는 경우의 클리어 던전 횟수를 반환하는 문제
- 입장 조건 최소 피로도로 인해 변수가 많아 모든 경우의 수를 구해야 함
-> DFS 알고리즘을 이용해 모든 경우의 수를 구함
https://godgjwnsgur7.tistory.com/47
풀이 과정
using System;
public class Solution
{
public int solution(int k, int[,] dungeons)
{
int answer = 0; // 최대로 클리어 할 수 있는 던전 개수
var boolArray = new bool[dungeons.GetLength(0)]; // 방문 배열
DFS(dungeons, k, boolArray, 0, ref answer); // 완전탐색
return answer;
}
public void DFS(int[,] dungeons, int k, bool[] boolArray, int clearCount, ref int answer)
{
for(int i = 0; i < dungeons.GetLength(0); i++)
{
// 이미 클리어 했거나 클리어 할 수 없는 던전이라면
if(boolArray[i] || k < dungeons[i, 0])
continue;
boolArray[i] = true;
DFS(dungeons, k - dungeons[i, 1], boolArray, clearCount + 1, ref answer);
boolArray[i] = false;
}
answer = Math.Max(answer, clearCount);
}
}
'CodingTest > Programmers Lv.2' 카테고리의 다른 글
[프로그래머스 C#] Lv.2 퍼즐게임 (PCCP 기출문제 2번) (1) | 2024.09.23 |
---|---|
[프로그래머스 C#] Lv.2 디펜스 게임 (0) | 2024.05.22 |
[프로그래머스 C#] Lv.2 과제 진행하기 (0) | 2024.05.22 |
[프로그래머스 C#] Lv.2 유사 칸토어 비트열 (0) | 2024.04.01 |
[프로그래머스 C#] Lv.2 혼자 놀기의 달인 (0) | 2024.03.20 |