Algorithm
-
프로그래머스(Programmers) LEVEL2 - JadenCase 문자열 만들기Algorithm/Problems_Solving 2022. 10. 2. 10:21
''' s.split() vs s.split(" ") ex) s = " 3people unFollowed me" s.split() 는 => ['3people', 'unFollowed', 'me'] s.split(" ")는 => ['', '', '3people', 'unFollowed', 'me'] ''' # 1st def solution(s): s = s.split(" ") return " ".join([strs[0].upper()+strs[1:].lower() if len(strs) > 0 else strs for strs in s]) # 다른사람풀이 def solution(s): s = s.split(" ") for i in range(len(s)): s[i] = s[i][:1].upper() + s..
-
프로그래머스(Programmers) LEVEL2 - 행렬의곱셈Algorithm/Problems_Solving 2022. 10. 1. 11:34
X = [[1, 2], [4, 5], [3, 6]] 3 x 2 matrix이다. 첫번째 row는 X[0] , 첫번째 row의 첫번째 element는 X[0][0] Y = [[1,2,3],[4,5,6]] 2 x 3 matrix이다 두 행렬을 곱한다고 했을 때 X의 coolumns와 Y의 rows가 같아야 한다 arr1 = [[12,7,3], [4,5,6],[7 ,8,9]] # 3x3 matrix arr2 = [[5,8,1,2],[6,7,3,0],[4,5,9,1]] # 3x4 matrix # 1st solution def solution(arr1, arr2): answer = [[0 for _ in range(len(arr2[0]))] for _ in range(len(arr1))] for i in rang..
-
프로그래머스(Programmers) LEVEL2 - 최댓값과 최솟값Algorithm/Problems_Solving 2022. 10. 1. 09:44
1. 최댓값과 최솟값 # 1st def solution(s): answer = '' min_num, max_num = min(s.split()), max(s.split()) if int(min_num) and int(max_num) >=0: return min_num + " " + max_num else: return max_num + " " + min_num 정확성: 16.7 합계: 16.7 / 100.0 = > s.split()하고 안에 요소들을 int로 바꿔주지 않았기 때문에 s = "-1 10 12 4"의 max 값의 경우 4가 나옴 # 2nd def solution(s): answer = '' s = list(map(int,s.split())) min_num, max_num = min(s), m..
-
동적계획법(Dynamic Programming)Algorithm/Algorithm_Theory 2022. 9. 12. 11:49
Dynamic Programming이란?! 특정 값을 얻기 위해 매번 같은 결과를 반환하는 연산을 굳이 반복해서 수행한다면 문제를 효율적으로 해결할 수 없다.(재귀함수). 한 번 계산한 결과를 재활용하는 방식 Dynamic Programming 조건 1) 최적 부문 구조 (Optimal Substructure) - 부문 문제들의 최적의 답을 이용해서 기존 문제의 최적의 답을 구할 수 있다는 것 ex) 피보나치 5번째의 수, fib(5)..(1,1,2,3,5..) 를 구한다고 했을 때 fib(3)과 fib(4) 2) 중복되는 부분 문제(Overlapping Subproblems) - fib(7)을 알아내기 위해, fib(5)를 2번씩이나..fib(4)를 3번씩이나..구하는것 재귀함수(Recursive Fu..
-
백준(BaekJoon)_15657_N과 M(8)Algorithm/Problems_Solving 2022. 8. 27. 11:18
n,m = map(int, input().split()) num_list = list(map(int, input().split())) result = [] def func(idx): if len(result) == m: print(" ".join(map(str,result))) return else: num_list.sort() for idx in range(idx,len(num_list)): result.append(num_list[idx]) func(idx) result.pop() func(0)
-
백준(BaekJoon)_15656_N과 M(7)Algorithm/Problems_Solving 2022. 8. 27. 11:14
n,m = map(int, input().split()) num_list = list(map(int, input().split())) answer = [] def func(start): if m == len(answer): print(" ".join(map(str, answer))) else: num_list.sort() for i in range(start, n): answer.append(num_list[i]) func(0) answer.pop() func(0)
-
백준(BaekJoon)_15656_N과M(6)Algorithm/Problems_Solving 2022. 8. 27. 11:12
n,m = map(int, input().split()) num_list = list(map(int, input().split())) result = [] def func(start): if m == len(result): print(" ".join(map(str, result))) else: num_list.sort() for i in range(start, n): if num_list[i] not in result: result.append(num_list[i]) func(i) result.pop() func(0)
-
백준(BaekJoon)_15654_N과M(5)Algorithm/Problems_Solving 2022. 8. 23. 09:55
n, m = map(int, input().split()) num_list = list(map(int, input().split())) answer = [] def func(): if len(answer) == m: print(" ".join(map(str, answer))) else: num_list.sort() for i in range(len(num_list)): if num_list[i] not in answer: answer.append(num_list[i]) func() answer.pop() func()