본문 바로가기

전공지식

(21)
[백준][DP][10844] 쉬운 계단 수 URL : https://www.acmicpc.net/problem/10844 - 소스코드 public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[][] dp = new int[n+1][10]; for(int i=1; i
[백준][DP][11726] 2 x n 타일링 URL : https://www.acmicpc.net/problem/11726 소스코드 : public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] dp = new int[n+1]; dp[0] = 1; dp[1] = 1; for(int i=3; i
[알고스팟][완전탐색] 보글 게임 URL : https://algospot.com/judge/problem/read/BOGGLE 알고스팟에 보글 게임이라는 문제가 있다. 하지만 해당 문제는 주어진 조건 때문에 완전탐색으로는 풀 수 없다. 하지만 지금은 완전 탐색의 공부를 목적으로 문제를 푸는 것이기 때문에 완전 탐색으로 문제를 접근하겠다. - 소스코드 static char[][] map = new char[5][5]; static final int[] dx = {-1, -1, -1, 1, 1, 1, 0, 0}; static final int[] dy = {-1, 0, 1, -1, 0, 1, -1, 1}; //5 x 5 보글 게임 판의 해당 위치에서 주어진 단어가 시작하는지를 반환. static boolean hasWord(int y, i..
[JM북][완전탐색] n개의 원소 중 m개를 고르는 모든 조합을 찾는 알고리즘 n개의 원소 중 m개를 고르는 모든 조합을 찾는 알고리즘을 재귀함수를 이용해서 풀면 소스코드는 다음과 같다. - 소스코드 import java.util.ArrayList; public class Main { //n : 전체 원소의 수 //picked : 지금까지 고른 원소들의 번호 //toPick : 더 고를 원소의 수 //일 때, 앞으로 toPick개의 원소를 고르는 모든 방법을 출력한다. static void pick(int n, ArrayList picked, int toPick){ //기저 사례 : 더 고를 원소가 없을 때 고른 원소들을 출력한다. if(toPick == 0){ System.out.println(picked); return; } //고를 수 있는 가장 작은 번호를 계산한다. int..
SwapPairs 문제 24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. Subscribe to see which companies asked this question 해석 : 연결된 목록이 있으면 인접한 두 노드를 서로 바꾸고 head를 반환하십시오.예를 들어..