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 | 31 |
Tags
- 17070번
- Beakjoon
- C#
- 2870번 c++
- Lv2
- 백준 17070번 c++
- 2870번
- 백준 2870번
- 백준 1103번 게임
- dfs
- 유니티
- Lv.3
- 프로그래머스
- 백준 c++ 2870번
- 백준
- 백준 c++ 2468번
- 2468 c++
- c++
- Algorithm
- 백준 1103번 c++
- 2870번 수학숙제 c++
- 코테
- 백준 17070번
- 수학숙제
- 백준 1103번
- 플레이어 이동
- 오브젝트 풀링
- 코딩테스트
- 2870번 수학숙제
- Unity
Archives
- Today
- Total
주녘공부일지
[프로그래머스 C#] Lv.3 양과 늑대 본문
https://school.programmers.co.kr/learn/courses/30/lessons/92343
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 정답코드 및 핵심 아이디어, 유의사항
조건에 따라 가장 많은 양을 데리고 올 수 있는 경우를 구하는 문제
- 단방향 그래프 // 노드 개수 - 1 = 간선 수
- 이동할 수 있는 노드에 대해서 DFS 알고리즘을 적용
DFS) BackTracking
https://godgjwnsgur7.tistory.com/47
[Algorithm C#] BFS, DFS ( + Back Tracking )
1. BFS(Breadth First Search) - 너비 우선 탐색최단 경로, 임의의 경로를 찾고 싶을 때, 등에 사용- 큐(FIFO) 사용 // 큐를 이용 public void BFS(int index) { Node root = nodes[index]; Queue queue = new Queue(); queue.Enqueue(root);
godgjwnsgur7.tistory.com
풀이 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution
{
public void DFS(ref int[] info, ref int[,] edges, ref bool[] boolArray
, ref int answer, int sheepCount, int wolfCount)
{
if(sheepCount <= wolfCount)
return;
answer = Math.Max(answer, sheepCount);
for(int i = 0; i < edges.GetLength(0); i++)
{
int parentNode = edges[i, 0];
int childNode = edges[i, 1];
if(boolArray[parentNode] && !boolArray[childNode])
{
boolArray[childNode] = true;
if(info[childNode] == 1)
DFS(ref info, ref edges, ref boolArray, ref answer, sheepCount, wolfCount + 1);
else
DFS(ref info, ref edges, ref boolArray, ref answer, sheepCount + 1, wolfCount);
boolArray[childNode] = false;
}
}
}
public int solution(int[] info, int[,] edges)
{
int answer = 0;
bool[] boolArray = new bool[info.Length];
boolArray[0] = true;
DFS(ref info, ref edges, ref boolArray, ref answer, 1, 0);
return answer;
}
}
'CodingTest > Programmers Lv.3' 카테고리의 다른 글
[프로그래머스 C#] Lv.3 연속 펄스 부분 수열의 합 (0) | 2024.10.11 |
---|---|
[프로그래머스 C#] Lv.3 미로 탈출 명령어 (0) | 2024.10.11 |
[프로그래머스 C#] Lv.3 디스크 컨트롤러 (0) | 2024.05.22 |
[프로그래머스 C#] Lv.3 모두 0으로 만들기 (1) | 2024.04.10 |
[프로그래머스 C#] Lv.3 기지국 설치 (0) | 2024.04.09 |