[백준] 1062번: 연결 요수의 개수 (JavaScript)
·
PS
문제https://www.acmicpc.net/problem/11724개념그래프 탐색DFS, BFS구현 코드(JavaScript)const fs = require('fs');let input = fs.readFileSync('/dev/stdin').toString().trim().split('\n');const [n, m] = input[0].split(' ').map(Number);const graph = Array(n + 1) .fill(0) .map(() => Array(n + 1).fill(0));for (let i = 1; i { const queue = [start]; visited[start] = true; while (queue.length) { const node = qu..
[백준] 2667번: 단지번호붙이기
·
PS
문제https://www.acmicpc.net/problem/2667  개념그래프, DFS, BFS  실행 결과     구현 코드(c++)#include #include #include #include using namespace std;int g[25][25];bool v[25][25];int dx[4] = {-1, 1, 0, 0};int dy[4] = {0, 0, -1, 1};int n;int dfs(int x, int y) { int cnt = 1; v[x][y] = true; for (int i = 0; i = 0 && ny >= 0 && nx > n; cin.ignore(); for (int i = 0; i danzis; int cnt = 0; for (int i = 0; i   ..
[프로그래머스] 타겟 넘버
·
PS
문제https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  개념DFS  실행 결과    구현 코드(JavaScript)function solution(numbers, target) { function dfs(index, sum) { // 다 돌았을 때 합이 target과 같으면 1, 아니면 0을 반환 if (index === numbers.length) { return sum === target ? 1 : 0; } ..
[백준] 1260번: DFS와 BFS
·
PS
문제https://www.acmicpc.net/problem/1260  개념그래프, DFS, BFS  실행 결과     구현 코드(c++)#include #include #include #include using namespace std;vector> graph; // 2차원 벡터로 선언vector visited; // 방문 처리용 배열 선언// 깊이 우선 탐색: 스택 재귀void dfs(int x) { visited[x] = true; cout q; visited[start] = true; // 현재 노드 방문 처리 q.push(start); // 넣기 while (!q.empty()) { int x = q.front(); // 가장 먼저 들어온 원소 확인 q.pop(); // ..