-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/StudyAlgorithmTeam/Season3
- Loading branch information
Showing
9 changed files
with
269 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# N차원 여행 | ||
|
||
|
||
MAX_M = 50 | ||
|
||
N = int(input()) | ||
M = int(input()) | ||
indicies = list(map(int, input().split())) | ||
steps = [(1 if c == '+' else -1) for c in input().strip()] | ||
|
||
hash_index = { | ||
idx: i | ||
for i, idx in enumerate(set(indicies)) | ||
} | ||
|
||
try: | ||
vector_history = [[0] * M] | ||
for i in range(M): | ||
vector = vector_history[-1].copy() | ||
idx = hash_index[indicies[i]] | ||
vector[idx] = vector_history[-1][idx] + steps[i] | ||
# 해당 vector를 이미 방문한 적 있는지 검사 | ||
for j in range(i): | ||
if vector_history[j] == vector: | ||
raise ValueError | ||
vector_history.append(vector) | ||
except ValueError: | ||
print(0) | ||
else: | ||
print(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# 카드 정렬하기 | ||
|
||
import sys | ||
from heapq import heappop, heappush, heapify | ||
|
||
|
||
N, *heap = map(int, sys.stdin.read().split()) | ||
|
||
heapify(heap) | ||
n_total_compares = 0 | ||
|
||
while len(heap) > 1: | ||
n_compares = heappop(heap) + heappop(heap) | ||
heappush(heap, n_compares) | ||
n_total_compares += n_compares | ||
|
||
print(n_total_compares) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 추월 | ||
|
||
from collections import deque | ||
import sys | ||
|
||
|
||
N = int(sys.stdin.readline()) | ||
|
||
# 터널은 사실상 FIFO 구조. | ||
tunnel = deque() | ||
overspeeded_cars = set() | ||
|
||
# 터널에 들어가는 차량을 Queue에 넣음 | ||
for i in range(N): | ||
car = sys.stdin.readline().strip() | ||
tunnel.append(car) | ||
|
||
# 터널에서 나온 차량을 Queue에서 제거해가며 비교 | ||
for i in range(N): | ||
# 터널에서 나온 차량 | ||
car = sys.stdin.readline().strip() | ||
|
||
# 이미 터널을 나왔던 (과속) 차량들은 Queue에서 제거 | ||
while tunnel[0] in overspeeded_cars: | ||
tunnel.popleft() | ||
|
||
if tunnel[0] == car: | ||
tunnel.popleft() | ||
else: | ||
# 나와야 할 순서대로 나온 것이 아닌 경우 = 추월한 경우 | ||
overspeeded_cars.add(car) | ||
|
||
print(len(overspeeded_cars)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
|
||
int C, N; | ||
cin >> C >> N; | ||
|
||
int dp[100001] = { 0, }; | ||
|
||
int cost[20] = { 0, }; | ||
int cust[20] = { 0, }; | ||
for (int i = 0; i < N; i++) { | ||
cin >> cost[i] >> cust[i]; | ||
} | ||
//input | ||
|
||
for (int i = 0; i < N; i++) { | ||
for (int j = 0; j < 100001; j++) { | ||
if (j - cost[i] >= 0) //i번째 값을 빼도 0보다 같거나 크다면 | ||
dp[j] = max(dp[j], dp[j - cost[i]] + cust[i]); // 0/1 중 큰것을 선택 | ||
} | ||
} | ||
|
||
for (int j = 0; j < 100001; j++) { | ||
if (dp[j] >= C) { | ||
cout << j; | ||
break; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int L[20] = { 0, }; | ||
int J[20] = { 0, }; | ||
int N; | ||
int mem[20][101] = {0,}; | ||
|
||
int knap(int i, int hp) { | ||
if (hp <= 0) //죽으면 -100 | ||
return -100; | ||
if (i == N) //다 돌면 끝 | ||
return 0; | ||
if (mem[i][hp] != -1) // 이미 계산 | ||
return mem[i][hp]; | ||
mem[i][hp] = max((knap(i + 1, hp - L[i]) + J[i]), knap(i + 1, hp)); | ||
return mem[i][hp]; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
|
||
cin >> N; | ||
|
||
for (int i = 0; i < N; i++) { | ||
cin >> L[i]; | ||
} | ||
for (int i = 0; i < N; i++) { | ||
cin >> J[i]; | ||
} | ||
for (int i = 0; i < 20; i++) { | ||
for (int j = 0; j < 101; j++) { | ||
mem[i][j] = -1; | ||
} | ||
} | ||
|
||
cout << knap(0, 100); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
n = int(input()) #사람의 수 | ||
H = [0] + list(map(int, input().split())) #health | ||
J = [0] + list(map(int, input().split())) #joyful | ||
# list 1부터 시작. | ||
|
||
#dp 테이블 | ||
dp = [[0]* 101 for _ in range(n+1)] | ||
|
||
for x in range(1,n+1): | ||
h = H[x] | ||
j = J[x] | ||
for y in range(1,101): | ||
if y < h: #현재 사람 x | ||
dp[x][y] = dp[x-1][y] | ||
else: #현재 사람 o | ||
dp[x][y] = max(dp[x-1][y], dp[x-1][y-h]+ j) | ||
|
||
print(dp[n][99]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int c, n; | ||
int input[20][2]; | ||
int dp[100001]; | ||
|
||
int countDP(int customer, int cityNum) { | ||
int min = 100 * 1000; | ||
int cost; | ||
if (customer <= 0) return 0; | ||
else if (dp[customer] > 0) return dp[customer]; | ||
else { | ||
for (int i = 0; i < cityNum; i++) { | ||
cost = countDP(customer - input[i][1], cityNum) + input[i][0]; | ||
min = cost < min ? cost : min; | ||
} | ||
dp[customer] = min; | ||
return min; | ||
} | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(0); cout.tie(0); | ||
|
||
cin >> c >> n; | ||
for (int i = 0; i < n; i++) { | ||
int a, b; | ||
cin >> a >> b; | ||
input[i][0] = a; | ||
input[i][1] = b; | ||
} | ||
|
||
cout << countDP(c, n); | ||
|
||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
C,N = map(int,input().split()) | ||
arr_mony = [] | ||
arr_piple =[] | ||
|
||
for i in range(N): | ||
a,b = map(int,input().split()) | ||
arr_mony.append(a) | ||
arr_piple.append(b) | ||
|
||
result = [] | ||
|
||
def minmony(i,mony): | ||
if i >= C: | ||
result.append(mony) | ||
if i == N: | ||
i = 0 | ||
return max(arr_piple[i] + minmony(i+1, mony + arr_mony[i]), minmony(i+1,mony), arr_mony[i] + minmony(i, mony+arr_mony[i])) | ||
|
||
|
||
|
||
minmony(0,0) | ||
result.sort() | ||
print(result[0]) | ||
|
||
#넣는다. 안넣는다. 현재를 넣는다. | ||
#그리고 비용과 값을 같이 넣어서 비용이 가장 작은 것을 넣는다. |