Skip to content

Commit 897f6f7

Browse files
authored
Merge pull request #193 from AlgorithmStudy-Allumbus/YoonYn9915
YoonYn9915 / 4월 3주차 / 3문제
2 parents cc56216 + a1f5ef0 commit 897f6f7

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def check_password(password):
2+
num_vowel = sum(1 for c in password if c in 'aeiou')
3+
num_consonant = len(password) - num_vowel
4+
return num_vowel >= 1 and num_consonant >= 2
5+
6+
def recursion(start, depth, password):
7+
if depth == L:
8+
if check_password(password):
9+
answers.append(password)
10+
return
11+
12+
for i in range(start, len(letters)):
13+
recursion(i + 1, depth + 1, password + letters[i])
14+
15+
L, C = map(int, input().split())
16+
letters = sorted(input().split())
17+
answers = []
18+
19+
recursion(0, 0, '')
20+
21+
for ans in answers:
22+
print(ans)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import sys
2+
3+
inp = sys.stdin.readline
4+
5+
n = int(inp())
6+
7+
roads = list(map(int, inp().split()))
8+
oil_prices = list(map(int, inp().split()))
9+
10+
# 최소 비용
11+
answer = 0
12+
# 현재 도시
13+
loc = 0
14+
15+
while True:
16+
# 현재 도시보다 기름값이 적은 곳 찾기
17+
for i in range(loc + 1, n):
18+
if oil_prices[loc] > oil_prices[i] or i == n - 1:
19+
# 이곳까지 가기 위해 현재 도시에서 주유하면서 비용 소모
20+
# 현재 도시의 기름값 * i번 도시까지 가야 할 거리
21+
answer += oil_prices[loc] * sum(roads[loc:i])
22+
loc = i
23+
break
24+
25+
if loc == n - 1:
26+
break
27+
28+
print(answer)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
from itertools import combinations
3+
4+
inp = sys.stdin.readline
5+
6+
while True:
7+
arr = list(map(int, inp().split()))
8+
9+
# 0이면 종료
10+
if arr[0] == 0:
11+
break
12+
# 0이 아니면
13+
K = arr[0]
14+
# combinations 라이브러리를 사용해 집합 S에서 조합 생성
15+
answers = combinations(arr[1:K+1], 6)
16+
17+
for answer in answers:
18+
for num in answer:
19+
print(num, end=' ')
20+
print()
21+
22+
print()

0 commit comments

Comments
 (0)