728x90

전체 글 271

[프로그래머스] LV1. 가장 많이 받은 선뭉 | JAVA

https://school.programmers.co.kr/learn/courses/30/lessons/258712 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr   static int solution(String[] friends, String[] gifts) { int answer = 0; int num_fr = friends.length; Map map = new HashMap(); for(int i=0;i presents[j][i] || (presents[i][..

[프로그래머스] LV2. 택배 배달과 수거하기 | JAVA

https://school.programmers.co.kr/learn/courses/30/lessons/150369 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr class Solution { public long solution(int cap, int n, int[] deliveries, int[] pickups) { long answer = 0; int d=0; int p =0; for(int i=n-1;i>=0;i--){ d -= deliveries[i]; ..

[프로그래머스] LV.1 개인정보 수집 유효기간 | JAVA

https://school.programmers.co.kr/learn/courses/30/lessons/150370 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr static ArrayList solution(String today, String[] terms, String[] privacies) { ArrayList answer = new ArrayList(); Map map = new HashMap(); for(String str : terms){ map.put(str.split(" ")[0],In..

89 삐약 : 백준 15656| N과 M (7) [바킹독| 백트래킹 |JAVA]

https://www.acmicpc.net/problem/15656 package BKD_0x0C_BackTracking;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.StringTokenizer;public class BOJ_15656 { static int N; static int M; static int[] arr; static int[] input; static StringBuilder sb = new StringBuilder(); static void dfs(int depth){..

88 삐약 : 백준 15655| N과 M (6) [바킹독| 백트래킹 |JAVA]

https://www.acmicpc.net/problem/15655  package BKD_0x0C_BackTracking;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.StringTokenizer;public class BOJ_15655 { static int N; static int M; static int[] arr; static boolean[] visited; static int[] input; static void dfs(int depth, int at){ if(d..

87 삐약 : 백준 15654| N과 M (5) [바킹독| 백트래킹 |JAVA]

https://www.acmicpc.net/problem/15654  package BKD_0x0C_BackTracking;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.StringTokenizer;public class BOJ_15654 { static int N; static int M; static int[] arr; static boolean[] visited; static int[] input; static void dfs(int depth){ if(depth==M)..

백트래킹

백트래킹이란?- 노드의 유망성을 판단한 뒤 해당 노드가 유망하지 않다면 부모노드로 돌아가 다른 자식 노드를 찾는 방법.❗️즉, 모든 경우의 수를 찾아 보지만 그 중에서도 가능성 있는 경우의 수만 찾아보는 것을 의미❗️  백트래킹 vs dfs vs 브루트포스 1. 브루트 포스- 모든 경우의 수를 찾아본다.- 장점 : 만족하는 값을 100% 찾아냄- 단점 : 조합 가능 경우의 수에 따라 필요 자원 크기가 커 질 수 있음. 2. 백트래킹 - 해당 범위 내에서 조건을 추가하여 값의 유망성을 판단.- 장점 : 탐색에 불필요한 자원을 줄일 수 있다. (브루트 포스의 단점 보완) 3. dfs - 백트래킹에 사용되는 대표적인 탐색 알고리즘❗️ 백트래킹의 방법 중 하나가 dfs임 ❗️

728x90