반응형 다이나믹 프로그래밍3 [JAVA] 338. Counting Bits 목차 문제 Given an integer n, return an array ans of length n + 1 such that for each i (0 코딩테스트/알고리즘 문제풀이 2022. 9. 21. [JAVA] 70. Climbing Stairs 목차 문제 You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Example 2: Input: n = 3 Output: 3 Explanation: There are three ways to climb to the top. 1. 1 step + 1 step + 1 s.. 코딩테스트/알고리즘 문제풀이 2022. 9. 19. [JAVA] 다이나믹 프로그래밍 (Dynamic Programming) 목차 다이나믹 프로그래밍의 조건 최적 부분 구조 : 큰 문제를 작은 문제로 나눌 수 있으며 작은 문제의 답을 모아서 큰 문제를 해결할 수 있다. 중복되는 부분 문제 : 동일한 작은 문제를 반복적으로 해결해야 한다. 비효율적인 피보나치 수열 구현 import java.util.*; public class Main { // 피보나치 함수(Fibonacci Function)을 재귀함수로 구현 public static int fibo(int x) { if (x == 1 || x == 2) { return 1; } return fibo(x - 1) + fibo(x - 2); } public static void main(String[] args) { System.out.println(fibo(4)); } } 탑다.. ETC/자료구조 이론 2022. 9. 19. 이전 1 다음 반응형