Skip to content
20 changes: 20 additions & 0 deletions 이코테/08 DP/1로_만들기/유진.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
x = int(input())
d = [0] * 30001

# 보텀업 방식
for i in range(2, x + 1):
# 1을 빼주는 경우
# i - 1보다 하나의 연산(-1)을 더해줘야 하므로 +1
d[i] = d[i - 1] + 1

# 2로 나눌경우
if i % 2 == 0:
d[i] = min(d[i], d[i//2] + 1)
# 3으로 나눌경우
elif i % 3 == 0:
d[i] = min(d[i], d[i//3] + 1)
# 5로 나눌경우
elif i % 5 == 0:
d[i] = min(d[i], d[i//5] + 1)

print(d[x])
20 changes: 20 additions & 0 deletions 이코테/08 다이나믹 프로그래밍/1로_만들기/유진.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
x = int(input())
d = [0] * 30001

# 보텀업 방식
for i in range(2, x + 1):
# 1을 빼주는 경우
# i - 1보다 하나의 연산(-1)을 더해줘야 하므로 +1
d[i] = d[i - 1] + 1

# 2로 나눌경우
if i % 2 == 0:
d[i] = min(d[i], d[i//2] + 1)
# 3으로 나눌경우
elif i % 3 == 0:
d[i] = min(d[i], d[i//3] + 1)
# 5로 나눌경우
elif i % 5 == 0:
d[i] = min(d[i], d[i//5] + 1)

print(d[x])
20 changes: 20 additions & 0 deletions 이코테/08 다이나믹 프로그래밍/개미_전사/유진.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
n = 4#int(input())
k = [1, 3, 1, 5]#list(map(int, input().split()))
d = [0] * 100 # i번째 창고를 털 때, 가장 많이 털수있는 양을 저장

# 최솟값 지정
d[0] = k[0]
# 어느 방부터 털기 시작하는게 많이털 수 있을까
d[1] = max(k[0], k[1])

# 이후에는 점화식으로 for문
# di = max(di-1, di-2 + ki)
# 바로 전 방을 터는게 많을까, 그전전방과 현재 방을 같이 터는게 많을까
for i in range(2, n):
d[i] = max(d[i - 1], d[i - 2] + k[i])

print(d[n - 1])

# 몰라서 봤음
# d[i] = max(k[i - 1], k[i - 1] + k[i])
# 접근만 좋았음(식은 결국 틀림)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Arrays;
import java.util.Scanner;

public class 준호 {
public static void main(String[] args) {
// 효율적인 화폐 구성
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
int[] number = new int[N];
for (int i = 0; i < N; i++) {
number[i] = scanner.nextInt();
}

int[] total = new int[M+1];
Arrays.fill(total, 10001);

total[0] = 0;
for (int i = 0; i < N; i++) {
for (int j = number[i]; j <= M; j++) {
if (total[j - number[i]] != 10001) {
total[j] = Math.min(total[j], total[j - number[i]] + 1);
}
}
}
if (total[M] != 10001) {
System.out.println(total[M]);
} else {
System.out.println(-1);
}
}
}
50 changes: 50 additions & 0 deletions 이코테/09 최단 경로/미래_도시/준호.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.util.*;

public class 준호 {
public static final int INF = (int) 1e9;
public static int N, M, X, K;
public static int[][] graph = new int[101][101];

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
N = scanner.nextInt();
M = scanner.nextInt();
for (int i = 0; i < 101; i++) {
Arrays.fill(graph[i], INF);
}
for (int a = 1; a <= N; a++) {
for (int b = 1; b <= N; b++) {
if (a == b) {
graph[a][b] = 0;
}
}
}

for (int i = 0; i < M; i++) {
int a = scanner.nextInt();
int b = scanner.nextInt();
graph[a][b] = 1;
graph[b][a] = 1;
}

X = scanner.nextInt();
K = scanner.nextInt();

for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
for (int k = 1; k <= N; k++) {
graph[i][j] = Math.min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
int distance = graph[1][K] + graph[K][X];

if (distance >= INF) {
System.out.println(-1);
} else {
System.out.println(distance);
}
}

}