├── source ├── eunbee │ ├── test2 │ ├── boj │ │ ├── .gitignore │ │ ├── .DS_Store │ │ ├── src │ │ │ └── .DS_Store │ │ ├── .classpath │ │ ├── .project │ │ └── .settings │ │ │ └── org.eclipse.jdt.core.prefs │ ├── .gitignore │ └── .DS_Store ├── kim-dabin │ ├── [백준 │ ├── [해커랭크 │ ├── coding-test │ │ └── kakao │ │ │ ├── [카카오 │ │ │ ├── [카카오2018 │ │ │ ├── [카카오2020 │ │ │ └── [프로그래머스 │ ├── BJ_2133.md │ ├── BJ_2156.md │ ├── Prog_2XNTiling.md │ ├── BJ_1495.md │ ├── BJ_14501.md │ ├── BJ_11403.md │ ├── java_BJ11403.md │ └── HR_CountingValleys.md ├── woodi │ ├── test1.txt │ ├── 201226_boj_2839.md │ ├── 201023_Programmers_42895.md │ ├── 200821_Ladder.md │ ├── 201023_Programmers_43238.md │ ├── 201101_Programmers_43105.md │ └── 20200915_boj_2294.md ├── .DS_Store ├── ohhako │ ├── imgs │ │ ├── array.JPG │ │ ├── array.png │ │ ├── tile.JPG │ │ ├── 1309그림.png │ │ ├── nodeBfs.png │ │ ├── queue1.JPG │ │ ├── 소수구하기결과.JPG │ │ ├── 큰수만들기결과.JPG │ │ ├── 하샤드수결과1.JPG │ │ ├── 하샤드수결과2.JPG │ │ ├── companyout.JPG │ │ ├── sameArrays.JPG │ │ ├── 2018_파일명정렬결과.JPG │ │ └── sameArrays2.JPG │ ├── boj │ │ ├── bj_1003.md │ │ ├── bj_1010.java │ │ ├── bj_2309.java │ │ ├── bj_11052.md │ │ ├── bj_1149.java │ │ ├── bj_11333.md │ │ ├── bj_1945.md │ │ ├── bj_1018.java │ │ ├── bj_1722.md │ │ └── bj_1010.md │ ├── coding test │ │ ├── imgs │ │ │ ├── 압축.png │ │ │ └── 압축결과.JPG │ │ ├── LINE │ │ │ └── [LINE]2019상반기인턴채용.md │ │ ├── 200809_test2.md │ │ ├── 200809_test3.md │ │ ├── kakao │ │ │ ├── 2019_징검다리건너기.md │ │ │ ├── 2020_외벽점검.md │ │ │ ├── 자물쇠와열쇠.java │ │ │ └── 2019_오픈채팅방.java │ │ ├── 2018_summerCoding3.md │ │ ├── 2018_summerCoding2.md │ │ └── 200226_queue.md │ ├── solution template.md │ ├── 200607_dp.md │ ├── 200526_영어끝말잇기.md │ ├── 200208_array&string.md │ ├── 200429_dp.md │ └── 200208_number.md ├── JmKanmo │ ├── 코딩테스트 │ │ ├── 문제캡처.zip │ │ ├── 11번가코테(1번).cpp │ │ ├── 카카오인턴1번.cpp │ │ └── 카카오인턴3번.cpp │ └── PS(Korean) │ │ ├── BST.cpp │ │ ├── boj1316.cpp │ │ ├── boj13549.cpp │ │ ├── boj15661.cpp │ │ ├── boj2636(치즈).cpp │ │ ├── boj14226(이모티콘).cpp │ │ ├── BOJ-17406(배열돌리기4).cpp │ │ ├── boj1568.cpp │ │ ├── boj2749.cpp │ │ ├── boj1302.cpp │ │ ├── boj1300.cpp │ │ ├── boj12738(LIS-lower_bound).cpp │ │ ├── boj1668.cpp │ │ ├── boj1543.cpp │ │ ├── boj2941(크로아티아 알파벳).cpp │ │ ├── boj11055.cpp │ │ ├── boj18511.cpp │ │ ├── boj1339(단어수학-탐욕법).cpp │ │ ├── 소수만들기.cpp │ │ ├── boj3040.cpp │ │ ├── boj17087(숨바꼭질6).cpp │ │ ├── boj9935(문자열폭발-배열).cpp │ │ ├── boj14003.cpp │ │ ├── 소수찾기.cpp │ │ ├── boj13023.cpp │ │ ├── boj9455.cpp │ │ ├── boj1236.cpp │ │ ├── boj1167.cpp │ │ ├── boj5567.cpp │ │ ├── boj2110.cpp │ │ ├── boj1991.cpp │ │ ├── boj4195.cpp │ │ ├── boj16637.cpp │ │ ├── boj12852.cpp │ │ ├── boj13913.cpp │ │ ├── boj14002.cpp │ │ ├── BOJ-16948 데스나이트.cpp │ │ ├── boj1074(재귀).cpp │ │ ├── boj1939(kruskal).cpp │ │ ├── boj14267.cpp │ │ ├── boj10830.cpp │ │ ├── boj12851.cpp │ │ ├── boj1062.cpp │ │ ├── boj1389.cpp │ │ ├── 숨바꼭질5.cpp │ │ ├── boj1339(단어수학-완탐).cpp │ │ ├── boj9742(순열).cpp │ │ ├── boj9935(문자열폭발-스택).cpp │ │ └── boj2667.cpp ├── lee │ ├── 200308_dp.md │ ├── 200326_hash.md │ ├── 200310_hash.md │ ├── 200319_sort.md │ ├── 200304_sort.md │ ├── 200324_hashmap.md │ ├── 200318_dp.md │ ├── team │ │ ├── 20200607_숫자게임.md │ │ ├── 200409_기타리스트.md │ │ ├── 20200427_타일채우기.md │ │ ├── 20200503_로또.md │ │ ├── 200402_NumberPrinting.md │ │ ├── 200325_dp.md │ │ ├── 200331_코니와 문의 술래잡기.md │ │ └── 20200419_카카오.md │ ├── 200312_priorityQueue.md │ ├── 200326_hashmap.md │ ├── 200227_hash.md │ ├── 200314_dfs.md │ ├── 200309_dp.md │ ├── 200225_practice.md │ ├── 200312_priorityQueue2.md │ ├── 200317_dp.md │ └── 200305_sort.md ├── soyeon │ ├── [programmers]12900.md │ ├── [boj] 2294.md │ ├── [programmers]43105.md │ ├── [programmers]43165.md │ ├── [boj]2156.md │ ├── [programmers] 43105.md │ ├── [boj]2022.md │ ├── [programmers]12981.md │ ├── [programmers]12987.md │ ├── [boj]11403.md │ ├── [programmers] 17681.md │ ├── [programmers] 42895.md │ ├── [boj] 2110.md │ ├── [programmers] 64065.md │ ├── [leetcode]55.md │ ├── [programmers] 43238.md │ ├── [programmers] 64062.md │ ├── [programmers] 43163.md │ └── [programmers] 42898.md ├── lukas │ ├── 26032020_PriceStack.md │ ├── 18032020_CaesarCipher.md │ ├── 26032020_PipeStack.md │ ├── 17032020_Greedy.md │ ├── 03032020_PrinterQueue.md │ ├── 04032020_TowerStack.md │ └── 19032020_ProgressQueue.md └── diane │ └── [baekjoon]2839.md ├── .gitignore ├── .vs ├── ProjectSettings.json ├── slnx.sqlite ├── VSWorkspaceState.json └── algorithm-study │ └── v15 │ ├── .suo │ └── Browse.VC.db ├── imgs ├── Thumbs.db ├── heap결과.png ├── stack.png ├── heapData.png ├── hashStructure.PNG └── lee │ ├── 20200503_lotto.png │ └── 20200427_tileGrout.png ├── contents ├── stack.hwp ├── 이분탐색.md ├── 우선순위큐.md ├── 수학이론.md ├── cache memory change.md ├── 정렬.md ├── 기본정렬.md ├── Heap.md ├── divide_and_conquer.md ├── hashing.md ├── search요약.md └── greedy.md ├── docs ├── github │ ├── imgs │ │ ├── 1init.JPG │ │ ├── 5목록확인.JPG │ │ ├── 명령어전체샷.JPG │ │ ├── 6checkout.JPG │ │ ├── 2remote원격저장소.JPG │ │ ├── 3branch목록확인.JPG │ │ ├── 4remoteUpdate.JPG │ │ ├── createBranch1.JPG │ │ └── fork_repository_update.png │ ├── update_forkedRepo_from_originRepo.md │ └── howToCreate_branch.md ├── java │ ├── img │ │ ├── 2018_파일명정렬결과.jpg │ │ ├── java-memory.JPG │ │ └── java_memory.jpg │ ├── 수학적접근.md │ ├── String사용클래스비교.md │ ├── priorityQueue.md │ └── heap.java ├── 서로 다른 언어로 알고리즘 함께 공부하기.md └── study reference.md ├── solution template.md └── solution example.md /source/eunbee/test2: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/kim-dabin/[백준: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/kim-dabin/[해커랭크: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/woodi/test1.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | *.iml -------------------------------------------------------------------------------- /source/eunbee/boj/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | -------------------------------------------------------------------------------- /source/eunbee/.gitignore: -------------------------------------------------------------------------------- 1 | /.metadata/ 2 | -------------------------------------------------------------------------------- /source/kim-dabin/coding-test/kakao/[카카오: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/kim-dabin/coding-test/kakao/[카카오2018: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/kim-dabin/coding-test/kakao/[카카오2020: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /source/kim-dabin/coding-test/kakao/[프로그래머스: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.vs/ProjectSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "CurrentProjectSetting": "구성 없음" 3 | } -------------------------------------------------------------------------------- /.vs/slnx.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/.vs/slnx.sqlite -------------------------------------------------------------------------------- /imgs/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/Thumbs.db -------------------------------------------------------------------------------- /imgs/heap결과.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/heap결과.png -------------------------------------------------------------------------------- /imgs/stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/stack.png -------------------------------------------------------------------------------- /contents/stack.hwp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/contents/stack.hwp -------------------------------------------------------------------------------- /imgs/heapData.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/heapData.png -------------------------------------------------------------------------------- /source/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/.DS_Store -------------------------------------------------------------------------------- /imgs/hashStructure.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/hashStructure.PNG -------------------------------------------------------------------------------- /source/eunbee/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/eunbee/.DS_Store -------------------------------------------------------------------------------- /.vs/VSWorkspaceState.json: -------------------------------------------------------------------------------- 1 | { 2 | "ExpandedNodes": [ 3 | "" 4 | ], 5 | "PreviewInSolutionExplorer": false 6 | } -------------------------------------------------------------------------------- /.vs/algorithm-study/v15/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/.vs/algorithm-study/v15/.suo -------------------------------------------------------------------------------- /docs/github/imgs/1init.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/1init.JPG -------------------------------------------------------------------------------- /docs/github/imgs/5목록확인.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/5목록확인.JPG -------------------------------------------------------------------------------- /docs/github/imgs/명령어전체샷.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/명령어전체샷.JPG -------------------------------------------------------------------------------- /imgs/lee/20200503_lotto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/lee/20200503_lotto.png -------------------------------------------------------------------------------- /source/eunbee/boj/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/eunbee/boj/.DS_Store -------------------------------------------------------------------------------- /source/ohhako/imgs/array.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/array.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/array.png -------------------------------------------------------------------------------- /source/ohhako/imgs/tile.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/tile.JPG -------------------------------------------------------------------------------- /docs/github/imgs/6checkout.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/6checkout.JPG -------------------------------------------------------------------------------- /docs/java/img/2018_파일명정렬결과.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/java/img/2018_파일명정렬결과.jpg -------------------------------------------------------------------------------- /docs/java/img/java-memory.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/java/img/java-memory.JPG -------------------------------------------------------------------------------- /docs/java/img/java_memory.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/java/img/java_memory.jpg -------------------------------------------------------------------------------- /source/JmKanmo/코딩테스트/문제캡처.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/코딩테스트/문제캡처.zip -------------------------------------------------------------------------------- /source/ohhako/imgs/1309그림.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/1309그림.png -------------------------------------------------------------------------------- /source/ohhako/imgs/nodeBfs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/nodeBfs.png -------------------------------------------------------------------------------- /source/ohhako/imgs/queue1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/queue1.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/소수구하기결과.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/소수구하기결과.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/큰수만들기결과.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/큰수만들기결과.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/하샤드수결과1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/하샤드수결과1.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/하샤드수결과2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/하샤드수결과2.JPG -------------------------------------------------------------------------------- /docs/github/imgs/2remote원격저장소.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/2remote원격저장소.JPG -------------------------------------------------------------------------------- /docs/github/imgs/3branch목록확인.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/3branch목록확인.JPG -------------------------------------------------------------------------------- /imgs/lee/20200427_tileGrout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/imgs/lee/20200427_tileGrout.png -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/BST.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/BST.cpp -------------------------------------------------------------------------------- /source/eunbee/boj/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/eunbee/boj/src/.DS_Store -------------------------------------------------------------------------------- /source/ohhako/imgs/companyout.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/companyout.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/sameArrays.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/sameArrays.JPG -------------------------------------------------------------------------------- /docs/github/imgs/4remoteUpdate.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/4remoteUpdate.JPG -------------------------------------------------------------------------------- /docs/github/imgs/createBranch1.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/createBranch1.JPG -------------------------------------------------------------------------------- /source/ohhako/boj/bj_1003.md: -------------------------------------------------------------------------------- 1 | # 백준 동적프로그래밍(DP) 문제 2 | - 피보나치 함수(1003) 3 | - https://www.acmicpc.net/problem/1003 4 | 5 | ## 풀이 방법 -------------------------------------------------------------------------------- /source/ohhako/imgs/2018_파일명정렬결과.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/2018_파일명정렬결과.JPG -------------------------------------------------------------------------------- /source/ohhako/imgs/sameArrays2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/imgs/sameArrays2.JPG -------------------------------------------------------------------------------- /.vs/algorithm-study/v15/Browse.VC.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/.vs/algorithm-study/v15/Browse.VC.db -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1316.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/boj1316.cpp -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj13549.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/boj13549.cpp -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj15661.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/boj15661.cpp -------------------------------------------------------------------------------- /source/ohhako/coding test/imgs/압축.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/coding test/imgs/압축.png -------------------------------------------------------------------------------- /source/ohhako/coding test/imgs/압축결과.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/ohhako/coding test/imgs/압축결과.JPG -------------------------------------------------------------------------------- /docs/github/imgs/fork_repository_update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/docs/github/imgs/fork_repository_update.png -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj2636(치즈).cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/boj2636(치즈).cpp -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj14226(이모티콘).cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/boj14226(이모티콘).cpp -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/BOJ-17406(배열돌리기4).cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCopiens/algorithm-study/HEAD/source/JmKanmo/PS(Korean)/BOJ-17406(배열돌리기4).cpp -------------------------------------------------------------------------------- /source/ohhako/coding test/LINE/[LINE]2019상반기인턴채용.md: -------------------------------------------------------------------------------- 1 | 2 | --- 3 | 아래의 사이트를 참고해 작성된 글입니다. 4 | - https://engineering.linecorp.com/ko/blog/2019-firsthalf-line-internship-recruit-coding-test/ 5 | - https://deepwelloper.tistory.com/118 -------------------------------------------------------------------------------- /contents/이분탐색.md: -------------------------------------------------------------------------------- 1 | # 이분탐색 2 | 3 | - 사용 조건: 정렬된 배열에서 데이터를 찾아야 할 떄. 4 | - 완전탐색에서 매 반복마다 탐색 범위를 반으로 줄여가며 찾아가는 탐색 방법 5 | - 예를들어 `1 2 3 4 5 6 7 8 9 10`에서 8을 찾고 싶을때 정가운데 값 5를 찾은 후 왼쪽은 쳐다보지 않고 5의 오른쪽을 탐색 범위로 한다. 6 | 7 | 문제 목록 8 | https://www.acmicpc.net/problem/2110
9 | -------------------------------------------------------------------------------- /solution template.md: -------------------------------------------------------------------------------- 1 | 문제 회고를 위해 알고리즘 풀이 기록을 남깁니다. 2 | 3 | # OO사 OO 문제 4 | 5 | - 문제이름 6 | - URL 7 | 8 | ### 문제 이해하기 9 | 10 | ### 문제 접근 방법 11 | 12 | ### 구현 배경 지식 13 | 14 | ### 접근 방법을 적용한 코드 15 | ```java 16 | ``` 17 | 18 | ### 해결하지 못한 이유 19 | 20 | ### 문제를 해결한 코드 21 | ```java 22 | ``` 23 | 24 | ### 문제를 해결한 방법 25 | 26 | 27 | -------------------------------------------------------------------------------- /source/ohhako/solution template.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 스택/큐 문제 2 | - 문제이름 3 | - URL 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | 8 | ### 문제 접근 방법 9 | 10 | ### 구현 배경 지식 11 | 12 | ### 접근 방법을 적용한 코드 13 | ```java 14 | ``` 15 | 16 | ### 해결하지 못한 이유 17 | 18 | ### 문제를 해결한 코드 19 | ```java 20 | ``` 21 | 22 | ### 문제를 해결한 방법 23 | 24 | --- 25 | 아래의 사이트를 참고해 작성된 글입니다. 26 | -------------------------------------------------------------------------------- /contents/우선순위큐.md: -------------------------------------------------------------------------------- 1 | ## 우선순위 큐(Priority Queue) 요약 정리 2 | - 데이터 삽입 순서와 관계없이 우선순위가 가장 높은 데이터가 먼저 나오는 자료구조이다. 3 | - 데이터에 근거해 우선순위를 판단한다. 4 | - 우선순위가 같을수도 있다. 5 | - 자바에서 Priority queue API를 지원한다. 6 | 7 | ### 우선순위 큐 구현하기 8 | - 직접 구현하는 방법은 3가지 9 | - 배열 기반: 데이터 삽입/삭제 시 위치 일제히 이동필요, 삽입할때 삽입 위치를 찾기 위해 저장된 모든 데이터와 우선순위 비교 10 | - 연결리스트 기반: 삽입 위치를 찾기 위해 모든 노드를 방문해 우선순위를 비교 11 | - 힙 이용: 성능을 위한 일반적 구현방법 12 | -------------------------------------------------------------------------------- /source/eunbee/boj/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /source/eunbee/boj/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | boj 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /contents/수학이론.md: -------------------------------------------------------------------------------- 1 | # 수학이론 2 | 3 | ### 에라토스테네스의 체(소수 증명) 4 | - n이 소수라면 1, n 이외의 숫자로 나누었을때 0으로 딱 떨어지지 않는다.
5 | - n이 소수임을 증명하기 위해서 2~n-1 까지 나누어 볼 필요 없이 루트n 까지만 확인하면 된다.
6 | - 증명 7 | - 모든 n = a X b 관계를 가진다. 8 | - n이 소수가 아니면 a나 b로 나뉜다. 그런데 a나 b중에 크지 않은 쪽은 최대 루트n의 값을 갖는다. 9 | - 그래서 2부터 루트n 까지 검사해 나뉘는 수가 있으면 n은 소수가 아니다. 10 | 11 | ### 유클리드 알고리즘 (최대공약수 관련 이론) 12 | - a,b 가 있을때 a가 b의 배수이면 두 수의 최대 공약수는 b이다. 13 | - a를 b로 나누었을때 나머지가 p면 두 수의 최대 공약수는 b와 p의 최대공약수와 같다. 14 | -------------------------------------------------------------------------------- /contents/cache memory change.md: -------------------------------------------------------------------------------- 1 | # 캐시 메모리 교체 알고리즘 요약설명 2 | 3 | 4 | ### LRU(Least Recently Used) 5 | - 캐시 내에서 가장 오랫동안 참조되지 않은 블록을 교체하는 방식 6 | - 구현이 단순해 가장 널리 사용되는 알고리즘 7 | 8 | ### FIFO(Fisrt In First Out) 9 | - 먼저 들어온 블록이 먼저 교체되는 방식 10 | - 가장 먼저 들어온 블록은 필연적으로 가장 오래된 블록 11 | - 자주 사용되는 블록이 교체될 우려가 있다 12 | 13 | ### LFU(Least Frequency Used) 14 | - 사용 빈도수가 가장 적은 블록이 교체되는 방식 15 | - 블록의 사용 빈도수가 적다, 즉 가장 적게 참조 되었다는 의미 16 | - 최근 적재된 블록이 교체 될 우려가 있다 17 | 18 | ### Random 19 | - 교체될 블록이 임의로 선정되는 방식 20 | - 오버헤드가 적다 -------------------------------------------------------------------------------- /source/ohhako/coding test/200809_test2.md: -------------------------------------------------------------------------------- 1 | # OO사 OO 문제 2 | 3 | - 4번 4 | 5 | ### 문제 이해하기 6 | 7 | - Cache이론으로 접근해 최근 이용한 카드사의 트랜잭션을 출력하라 8 | - 캐시에 가장 최근에 사용한 데이터 순서로 남아있어야 한다. 9 | 10 | ### 문제 접근 방법 11 | 12 | 1. 공백 간격으로 파싱해 문자열 배열 생성 13 | 2. 입력순서가 유지되는 LinkedHashMap를 이용해 순서대로 저장 및 출력 14 | 3. 문자열 배열을 순회할 때마다 해시맵에 put, 전체 출력을 한다. 15 | 16 | ### 접근 방법을 적용한 코드 17 | 18 | ```java 19 | 20 | ``` 21 | 22 | ### 해결하지 못한 이유 23 | 24 | ### 문제를 해결한 코드 25 | 26 | ```java 27 | 28 | ``` 29 | 30 | ### 문제를 해결한 방법 31 | -------------------------------------------------------------------------------- /source/ohhako/coding test/200809_test3.md: -------------------------------------------------------------------------------- 1 | # OO사 OO 문제 2 | 3 | - 6번 4 | 5 | ### 문제 이해하기 6 | 7 | - 사방향 연속된 1을 테이블이라 가정하에 테이블 전체 둘레 (내부둘레/외부둘레) 합을 구하라 8 | 9 | ### 문제 접근 방법 10 | 11 | 1. ; 기준으로 문자열 파싱 12 | 2. 위에서 파싱한 문자열을 공백 기준으로 파싱 13 | 3. 외부둘레는 테이블 가로,세로를 알면 구할 수 있으므로 가장 처음 나오는 1을 기준으로 오른쪽 순회, 아래쪽 순회로 가로,세로를 구한다. 14 | 4. 내부 둘레가 여러개일 경우 어떻게 해결할 것인가? 15 | 16 | ### 접근 방법을 적용한 코드 17 | 18 | ```java 19 | 20 | ``` 21 | 22 | ### 해결하지 못한 이유 23 | 24 | ### 문제를 해결한 코드 25 | 26 | ```java 27 | 28 | ``` 29 | 30 | ### 문제를 해결한 방법 31 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1568.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cout.tie(0); 11 | cin.tie(0); 12 | 13 | int N; 14 | int cnt = 1; 15 | int time = 0; 16 | 17 | cin >> N; 18 | 19 | while (true) 20 | { 21 | if (N >= cnt) { 22 | N -= cnt; 23 | cnt++; 24 | time++; 25 | } 26 | else { 27 | cnt = 1; 28 | } 29 | if (N <= 0) break; 30 | } 31 | 32 | cout << time << endl; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj2749.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | ios_base::sync_with_stdio(0); 10 | cout.tie(0); 11 | cin.tie(0); 12 | 13 | long long n; 14 | int M = 1000000; 15 | int P = 15 * (M / 10); 16 | vectorfibo = vector(P + 1, 0); 17 | 18 | cin >> n; 19 | 20 | fibo[1] = 1; 21 | 22 | for (int i = 2; i <= P; i++) { 23 | fibo[i] = (fibo[i - 1] + fibo[i - 2])%M; 24 | } 25 | 26 | cout << fibo[n % P] << endl; 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /docs/github/update_forkedRepo_from_originRepo.md: -------------------------------------------------------------------------------- 1 | # Fork 한 Repository 최신으로 동기화 하는 방법 2 | 3 | ![img load fail](./imgs/fork_repository_update.png) 4 | 5 | ### 작업 설명 6 | 원본 repository로부터 최신 정보를 가져와 fork한 repository를 **업데이트 시키는** 작업이다. 동기화 작업이 완료되면 local, remote 저장소가 모두 Origin Repository의 **최신 상태**에 동기화된다. 7 | 8 | #### 요약 설명 9 | 1. $git remote add upstream 원본저장소URL 10 | 2. $git remote -v 11 | 3. $git fetch upstream 12 | 4. $git checkout master 13 | 5. $git merge upstream/master 14 | 6. $git push origin master 15 | -------------------------------------------------------------------------------- /source/lee/200308_dp.md: -------------------------------------------------------------------------------- 1 | # 타일 장식물 2 | https://programmers.co.kr/learn/courses/30/lessons/43104 3 | 4 | ## 문제 접근 방법 5 | N=1, N=2일때 값만 저장해두고 N=3이후부턴 저장된 값을 이용해 계산 6 | 7 | ### 해결한 코드 8 | ```java 9 | class Solution { 10 | public long solution(int N) { 11 | long[] answer = new long[N + 1]; 12 | answer[1] = 4; 13 | answer[2] = 6; 14 | for (int i = 3; i <= N; i++) { 15 | answer[i] = answer[i - 1] + answer[i - 2]; 16 | } 17 | return answer[N]; 18 | } 19 | } 20 | ``` 21 | ### Time complexity 22 | O(N) 23 | 24 | ### Space complexity 25 | O(N) 26 | -------------------------------------------------------------------------------- /docs/서로 다른 언어로 알고리즘 함께 공부하기.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### 서로 다른 언어로 알고리즘 함께 공부하기 4 | 5 | - 기존에 사용하던 언어 => Java 6 | 7 | - 새로 추가된 언어 => JavaScript 8 | 9 | - 제안하는 방법 10 | - 코드리뷰 시작 전 알고리즘 이론 정리/분석 설명하기 11 | - 팀원들과 이 알고리즘에 대해 얘기하는 시간 갖기 12 | - JavaScript로 문제를 푸는 것은 옵션! 13 | 14 | 15 | 16 | #### 어떤 알고리즘을 선택할 것인가? 17 | 18 | 기존 알고리즘 문제는 그날 문제 리뷰가 끝나고 다음 주에 어떤 문제를 풀지 얘기를 나누면서 선택한다. 19 | 20 | - 오늘의 알고리즘! (요즘 각광받고 있는 알고리즘이나 마이너한 알고리즘) 21 | 22 | - 기본적인 알고리즘 (BFS,DFS,DP...) 23 | 24 | - 팀원들이 푸는 문제와 관련있는 알고리즘 25 | 26 | 27 | 28 | #### 무엇을 설명할 것인가? 29 | 30 | - 동작 방식 31 | - 복잡도 32 | - 장/단점 33 | - 비슷한 알고리즘 유형 34 | - 대표적인 문제 소개 (풀이는 개인적으로 작성해 업로드) 35 | -------------------------------------------------------------------------------- /source/kim-dabin/BJ_2133.md: -------------------------------------------------------------------------------- 1 | # 타일 채우기 2 | 3 | https://www.acmicpc.net/problem/2133 4 | 5 | 6 | 7 | ## 소스 8 | 9 | ```java 10 | import java.util.*; 11 | 12 | public class Main { 13 | public static void main(String[] args) { 14 | Scanner scan = new Scanner(System.in); 15 | int n = scan.nextInt(); 16 | int [] dp = new int[n+1]; 17 | 18 | dp[0] = 1; 19 | for(int i=2; i<=n; i++) { //시작은 무조건 2칸 // 2*1 == 1*2 20 | dp[i] = 3*dp[i-2]; 21 | for(int j=i-4; j>=0; j-=2)//3*4 인경우 22 | dp[i]+=2*dp[j]; // dp[6] = 2*dp[2] // dp[6] = 2*dp[0] 23 | } 24 | System.out.println(dp[n]); 25 | } 26 | 27 | } 28 | 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1302.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(0); 13 | cout.tie(0); 14 | cin.tie(0); 15 | 16 | map hash_map; 17 | int N; 18 | cin >> N; 19 | 20 | for (int i = 0; i < N; i++) { 21 | string str; 22 | cin >> str; 23 | hash_map[str]++; 24 | } 25 | 26 | string title; 27 | int MAX = 0; 28 | 29 | for (auto elem : hash_map) 30 | { 31 | if (MAX < elem.second) { 32 | title = elem.first; 33 | MAX = elem.second; 34 | } 35 | } 36 | 37 | cout << title << endl; 38 | return 0; 39 | } -------------------------------------------------------------------------------- /source/soyeon/[programmers]12900.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | - 2 X N 타일링 3 | - https://programmers.co.kr/learn/courses/30/lessons/12900 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 직사각형 모양의 타일을 채우는 방법의 가짓 수를 구하는 문제이다. 8 | 9 | ### 문제 접근 방법 10 | - 이전 단계를 이용하여 다음 단계의 문제를 푼다. 11 | - 경우의 수를 구할 때 1000000007로 나눈 나머지를 구한다. 12 | - answer[i-2]에서 타일 2개를 배열하는 방법은 2가지이나 세로로 배열하는 방법은 answer[i-1]에 포함된다. 13 | 14 | ### 접근 방법을 적용한 코드 15 | ```java 16 | class Solution { 17 | public int solution(int n) { 18 | int answer[] = new int[n+1]; 19 | answer[1] = 1; 20 | answer[2] = 2; 21 | for(int i=3;i<=n;i++){ 22 | answer[i]=(answer[i-2]+answer[i-1])%1000000007; 23 | } 24 | return answer[n]; 25 | } 26 | } 27 | ``` 28 | -------------------------------------------------------------------------------- /source/lee/200326_hash.md: -------------------------------------------------------------------------------- 1 | # Ransom Note 2 | https://www.hackerrank.com/challenges/two-strings/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps 3 | 4 | ## 문제 접근 방법 5 | 6 | 7 | ## 코드 구현 8 | ```java 9 | class Solution { 10 | static String twoStrings(String s1, String s2) { 11 | Set set = new HashSet<>(); 12 | for (char c:s1.toCharArray()) set.add(c); 13 | 14 | for (char c:s2.toCharArray()){ 15 | if (set.contains(c)) return "YES"; 16 | } 17 | return "NO"; 18 | } 19 | } 20 | ``` 21 | 22 | ### Time complexity 23 | O(n+m) n=s1.length(), m=s2.length() 24 | 25 | ### Space complexity 26 | O(n+m) n=s1.length(), m=s2.length() 27 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1300.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(0); 15 | cout.tie(0); 16 | cin.tie(0); 17 | 18 | int N, K; 19 | cin >> N >> K; 20 | 21 | int left = 1, right = K, answer = 0; 22 | 23 | while (left <= right) 24 | { 25 | int mid = (left + right) / 2; 26 | long long cnt = 0; 27 | 28 | for (int i = 1; i <= N; i++) cnt += min(mid / i, N); 29 | 30 | if (cnt < K) 31 | left = mid + 1; 32 | else 33 | { 34 | answer = mid; 35 | right = mid - 1; 36 | } 37 | } 38 | 39 | cout << answer << endl; 40 | return 0; 41 | } -------------------------------------------------------------------------------- /contents/정렬.md: -------------------------------------------------------------------------------- 1 | # 정렬 알고리즘 2 | 3 | ## 1. 선택정렬 4 | 구하고자 하는 요소(min or max)를 찾아 swap하는 방식에서 착안하여 정렬에 '선택'이라는 이름이 붙었다. 5 | - 크기가 n인 일차원 배열에서 첫번쨰 인덱스를 i로 뽑는다. 6 | - i의 이후(i+1) 요소중 가장 작은 수(minIndex)를 선택해 i와 자리를 바꾼다. (swap) 7 | - i 다음의 인덱스에서 위 순서를 반복한다. 8 | - 복잡도 O(n^2) 9 | 10 | ## 2. 버블정렬 11 | 가장 가까운 인덱스끼리 비교하여 swap하는 과정이 거품이 이는 현상같아 '버블'이라는 이름이 붙었다. 12 | - 크기가 n인 일차원 배열 13 | - 인덱스 0부터 n-1까지 순회하며 i와 i+1 요소를 비교한다. 14 | - 배열을 한번 돌고나면 마지막 요소에는 가장 큰 수가 있다. 15 | - 마지막 인덱스를 하나씩 줄여가며 위 순서를 반복한다. 16 | - 복잡도 O(n^2) 17 | 18 | ## 3. 삽입정렬 19 | key를 주체로 삽입하는 알고리즘이다. 어떤 값 뒤에 key를 삽입할 것인가? 가 중요하다. 20 | - 크기가 n인 일차원 배열 21 | - key는 인덱스 1번부터 시작한다. 22 | - 배열을 인덱스 0부터 방문하며 key보다 크면 우측으로 모두 밀고 작으면 그 요소의 바로 뒤에 삽입한다. 23 | - 어느정도 정렬이 되어있는 경우에는 O(n^2)지만 최악의 평균적으로 복잡도 O(n^2)를 갖는다. 24 | - 밀어야 하는 요소가 많은 경우 i/o가 많이 일어나는 단점이 있다. -------------------------------------------------------------------------------- /source/JmKanmo/코딩테스트/11번가코테(1번).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(string S, string pattern) 9 | { 10 | int answer = 0; 11 | int patLen = pattern.length(); 12 | map hash_map; 13 | 14 | for (int i = 0; i < patLen; i++) hash_map[pattern[i]]++; 15 | 16 | for (int i = 0; i <= S.length() - patLen; i++) 17 | { 18 | maptemp_map; 19 | 20 | for (int j = i; j < i + patLen; j++) temp_map[S[j]]++; 21 | 22 | bool flag = true; 23 | 24 | for (auto elem : hash_map) 25 | { 26 | if (temp_map[elem.first] != elem.second) { 27 | flag = false; 28 | break; 29 | } 30 | } 31 | if (flag) { 32 | answer++; 33 | } 34 | } 35 | return answer; 36 | } 37 | -------------------------------------------------------------------------------- /contents/기본정렬.md: -------------------------------------------------------------------------------- 1 | # 기본정렬 알고리즘 2 | 3 | ## 1. 선택정렬 4 | 구하고자 하는 요소(min or max)를 찾아 swap하는 방식에서 착안하여 정렬에 '선택'이라는 이름이 붙었다. 5 | - 크기가 n인 일차원 배열에서 첫번쨰 인덱스를 i로 뽑는다. 6 | - i의 이후(i+1) 요소중 가장 작은 수(minIndex)를 선택해 i와 자리를 바꾼다. (swap) 7 | - i 다음의 인덱스에서 위 순서를 반복한다. 8 | - 복잡도 항상 O(n^2) 9 | 10 | ## 2. 버블정렬 11 | 가장 가까운 인덱스끼리 비교하여 swap하는 과정이 거품이 이는 현상같아 '버블'이라는 이름이 붙었다. 12 | - 크기가 n인 일차원 배열 13 | - 인덱스 0부터 n-1까지 순회하며 i와 i+1 요소를 비교한다. 14 | - 배열을 한번 돌고나면 마지막 요소에는 가장 큰 수가 있다. 15 | - 마지막 인덱스를 하나씩 줄여가며 위 순서를 반복한다. 16 | - 복잡도 항상 O(n^2) 17 | 18 | ## 3. 삽입정렬 19 | key를 주체로 삽입하는 알고리즘이다. 어떤 값 뒤에 key를 삽입할 것인가? 가 중요하다. 20 | - 크기가 n인 일차원 배열 21 | - key는 인덱스 1번부터 시작한다. 22 | - 배열을 인덱스 0부터 방문하며 key보다 크면 우측으로 모두 밀고 작으면 그 요소의 바로 뒤에 삽입한다. 23 | - 어느정도 정렬이 되어있는 경우에는 O(n)지만 최악의 평균적으로 복잡도 O(n^2)를 갖는다. 24 | - 밀어야 하는 요소가 많은 경우 i/o가 많이 일어나는 단점이 있다. -------------------------------------------------------------------------------- /source/lee/200310_hash.md: -------------------------------------------------------------------------------- 1 | # 완주하지 못한 선수 2 | - https://programmers.co.kr/learn/courses/30/lessons/42576 3 | 4 | ## 문제 접근 방법 5 | 6 | ### 문제점 7 | 8 | 9 | ## 코드 구현 10 | ```java 11 | import java.util.*; 12 | class Solution { 13 | public String solution(String[] participant, String[] completion) { 14 | Arrays.sort(participant); 15 | Arrays.sort(completion); 16 | for(int i=0; i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | ios_base::sync_with_stdio(0); 16 | cout.tie(0); 17 | cin.tie(0); 18 | 19 | int N; 20 | int answer = 0; 21 | vectorarr; 22 | arr.push_back(-2e9); 23 | 24 | cin >> N; 25 | 26 | for (int i = 0; i < N; i++) 27 | { 28 | int val; 29 | cin >> val; 30 | 31 | if (arr.back() < val) { 32 | arr.push_back(val); 33 | answer++; 34 | } 35 | else { 36 | auto it = lower_bound(arr.begin(), arr.end(), val); 37 | *it = val; 38 | } 39 | } 40 | cout << answer << endl; 41 | return 0; 42 | } -------------------------------------------------------------------------------- /docs/study reference.md: -------------------------------------------------------------------------------- 1 | 2 | ## 알고리즘 관련 사이트 3 | 4 | - 프로그래머스: https://programmers.co.kr/learn/challenges 5 | - HackerRank: https://www.hackerrank.com/ 6 | - 박트리: http://baactree.tistory.com/52 7 | - LeetCode: https://leetcode.com/ 8 | - 코드그라운드: https://www.codeground.org/about 9 | - 사이냅: http://euler.synap.co.kr/ 10 | - Topcoder: https://www.topcoder.com/ 11 | - 알고스팟: https://algospot.com/judge/problem/list/ 12 | - Baekjoon 알고리즘: https://www.acmicpc.net/ 13 | - SW Expert Academy: https://www.swexpertacademy.com/main/main.do 14 | - geeksforgeeks: https://www.geeksforgeeks.org/ 15 | - CodeForces: http://codeforces.com 16 | - 더블릿: http://59.23.150.58/ 17 | - HackerEarth: https://www.hackerearth.com/ 18 | - https://gmlwjd9405.github.io/2018/05/14/how-to-study-algorithms.html 19 | - https://gmlwjd9405.github.io/2018/05/14/how-to-study-algorithms.html 20 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1668.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(0); 12 | cout.tie(0); 13 | cin.tie(0); 14 | 15 | int N; 16 | cin >> N; 17 | vectorprize(N + 1); 18 | 19 | for (int i = 0; i < N; i++) { 20 | int val; 21 | cin >> val; 22 | prize[i] = val; 23 | } 24 | 25 | int left = 1, right = 1; 26 | 27 | for (int i = 0, MAX = prize[i]; i < N - 1; i++) { 28 | if (MAX < prize[i + 1]) { 29 | left++; 30 | MAX = prize[i + 1]; 31 | } 32 | } 33 | 34 | for (int i = N - 1, MAX = prize[i]; i > 0; i--) { 35 | if (prize[i - 1] > MAX) { 36 | right++; 37 | MAX = prize[i - 1]; 38 | } 39 | } 40 | 41 | cout << left << endl; 42 | cout << right << endl; 43 | return 0; 44 | } -------------------------------------------------------------------------------- /source/ohhako/coding test/kakao/2019_징검다리건너기.md: -------------------------------------------------------------------------------- 1 | # 카카오 2019 개발자 겨울 인턴쉽 코딩 테스트 2 | 3 | - 징검다리 건너기 4 | - https://programmers.co.kr/learn/courses/30/lessons/64062?language=java 5 | 6 | ### 문제 이해하기 7 | 8 | - 입력값: 징검다리의 각 디딤돌에 적힌 숫자 배열, 한 번에 건너뛸 수 있는 최대 칸수 k 9 | - 디딤돌 한번 딛을 때 마다 숫자가 1 내려간다. (0이면 x) 10 | - 무조건 가장 가까운 다리를 먼저 딛어야 한다. 11 | - 출력값: 최대로 건널 수 있는 사람 수 12 | 13 | ### 문제 접근 방법 14 | 15 | - 숫자가 작은 순서대로 인덱스를 배열에 저장한다. 16 | - 현재 인덱스를 i라고 할때 i이하,이상 인덱스의 거리 차이가 k 이하면 count 한다. 17 | 18 | ### 해결하지 못한 이유 19 | 20 | - 필연적으로 O(n2) 이상의 방법이고 잘못된 풀이라고 느꼈다. 21 | - 외부 솔루션 참조 22 | 23 | ### 문제를 해결한 방법 24 | 25 | - '이분탐색'을 응용한 '파라메트릭 서치' 26 | - 건널 수 있는 사람의 수를 min,max 로 설정하여 이진탐색을 진행한다. (logN) 27 | - 결정 함수는 그 인원이 건널 수 있는지 없는지 결정. 28 | 29 | ### 문제를 해결한 코드 30 | 31 | ```java 32 | 33 | ``` 34 | 35 | --- 36 | 37 | 참고 사이트 38 | 39 | - https://sarah950716.tistory.com/16 40 | -------------------------------------------------------------------------------- /source/eunbee/boj/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=14 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=14 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 13 | org.eclipse.jdt.core.compiler.release=enabled 14 | org.eclipse.jdt.core.compiler.source=14 15 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1543.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int answer; 9 | string str; 10 | string target; 11 | 12 | int getCntOfStr(int idx) 13 | { 14 | int cnt = 0; 15 | 16 | for (int i = idx; i < str.length(); i++) 17 | { 18 | string substr = str.substr(i, target.length()); 19 | if (substr == target) { 20 | cnt++; 21 | i += (target.length() - 1); 22 | } 23 | } 24 | return cnt; 25 | } 26 | 27 | void init() 28 | { 29 | getline(cin, str); 30 | getline(cin, target); 31 | } 32 | 33 | int main() 34 | { 35 | ios_base::sync_with_stdio(0); 36 | cout.tie(0); 37 | cin.tie(0); 38 | 39 | init(); 40 | 41 | for (int i = 0; i < str.length(); i++) { 42 | answer = max(answer, getCntOfStr(i)); 43 | } 44 | 45 | cout << answer << endl; 46 | return 0; 47 | } -------------------------------------------------------------------------------- /contents/divide_and_conquer.md: -------------------------------------------------------------------------------- 1 | # Divide and Conquer 알고리즘 2 | 3 | - '분할정복' 기법 이라고도 부릅니다. 4 | - 문제(problem)를 잘게 쪼개면서(sub-problem) 풀어나가고 다시 병합하며 해를 찾는 알고리즘 입니다. 5 | - 상위 문제를 구하기 위해 아래로 내려가며 답을 찾는 하향식 접근법 6 | - [divide and conquer](https://www.youtube.com/watch?v=2Rr2tW9zvRg) 7 | 8 | 9 | ### 알고리즘 설계 조언 10 | 1. Divide: 분할이 가능한 문제라면 분할 기준을 선택하여 문제를 2개 이상으로 나눈다. 11 | 2. Conquer: 분할이 불가능한 경우 문제를 푼다. 12 | 3. Combine: 정복한 문제를 병합하여 해를 찾는다. 제대로 나누면 병합하기도 쉽다. 13 | 14 | 15 | ### 알고리즘 효율성 16 | - 분할정복 알고리즘은 Recursion calls(재귀호출)가 사용되는 경우가 많다. 재귀호출에서 알고리즘 효율이 떨어질 수 있다. => 분할 기준에 따라 효율이 달라질 수 있다. 17 | 18 | 19 | ### 분할정복 관련 자료 20 | 21 | - [백준 Z](https://www.google.com/search?q=%EB%B0%B1%EC%A4%80+z+%EB%AC%B8%EC%A0%9C&oq=%EB%B0%B1%EC%A4%80+z+%EB%AC%B8%EC%A0%9C&aqs=chrome..69i57j0l9.3894j0j7&sourceid=chrome&ie=UTF-8) 22 | - [별 찍기 풀이](https://st-lab.tistory.com/95) 23 | - https://gamedevlog.tistory.com/58 24 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj2941(크로아티아 알파벳).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(0); 13 | cout.tie(0); 14 | cin.tie(0); 15 | 16 | maphash_map = 17 | { 18 | {"c=",1},{"c-",1},{"dz=",1},{"d-",1}, 19 | {"lj",1},{"nj",1},{"s=",1},{"z=",1} 20 | }; 21 | 22 | string str; 23 | int idx = 0; 24 | int cnt = 0; 25 | 26 | cin >> str; 27 | 28 | while (idx < str.length()) 29 | { 30 | string sub1 = str.substr(idx, 2); 31 | string sub2 = str.substr(idx, 3); 32 | 33 | if (hash_map.count(sub1)) { 34 | idx += 2; 35 | } 36 | else if (hash_map.count(sub2)) { 37 | idx += 3; 38 | } 39 | else { 40 | idx += 1; 41 | } 42 | cnt++; 43 | } 44 | cout << cnt << endl; 45 | return 0; 46 | } -------------------------------------------------------------------------------- /source/JmKanmo/코딩테스트/카카오인턴1번.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int solution(vector> board, vector moves) 9 | { 10 | int answer = 0; 11 | stackst; 12 | 13 | for (int i = 0; i < moves.size(); i++) 14 | { 15 | for (int j = 0; j < board.size(); j++) 16 | { 17 | if (board[j][moves[i] - 1]) 18 | { 19 | if (!st.empty() && board[j][moves[i] - 1] == st.top()) 20 | { 21 | answer += 2; 22 | st.pop(); 23 | } 24 | else { 25 | st.push(board[j][moves[i] - 1]); 26 | } 27 | board[j][moves[i] - 1] = 0; 28 | break; 29 | } 30 | } 31 | } 32 | return answer; 33 | } 34 | 35 | int main() 36 | { 37 | solution({ {0, 0, 0, 0, 0},{0, 0, 1, 0, 3},{0, 2, 5, 0, 1},{4, 2, 4, 4, 2},{3, 5, 1, 3, 1} }, 38 | { 1,5,3,5,1,2,1,4 }); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /source/ohhako/coding test/kakao/2020_외벽점검.md: -------------------------------------------------------------------------------- 1 | # 카카오 2020 블라인드 채용 코딩테스트 풀이 2 | - 외벽 점검 3 | - https://programmers.co.kr/learn/courses/30/lessons/60062 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 타원 n둘레의 벽에서 취약점을 모두 검사할 수 있는 친구들 최소인원을 구하라. (한시간 동안만) 8 | - 입력값: 외벽둘레 n / 친구들의 시간당 이동거리 배열/ 취약지점 배열 9 | - 첫번째 친구의 이동거리가 k일때 1시간 동안 k번 이동 가능하다. 10 | - 이때 친구들의 시작 자리는 지정 되어있지 않다. 11 | 12 | ### 문제 접근 방법 13 | - 취약지점의 각 사이 거리를 구해 배열 A에 저장했다. 14 | - 배열 A는 취약지점간의 거리이므로 크기가 -1 작다. 15 | - 배열A에서 시작 지점의 직전 지점과 검사끝난 지점의 다음 지점은 검사가 필요없는 특징을 이용한다. 16 | 17 | ### 해결하지 못한 이유 18 | - 1시간 동안 알고리즘을 고민해 보았지만 적합한 방법을 못찾았다. 19 | - 푼 사람들의 해설을 보니 bfs, BF로 풀더라. 20 | 21 | ### 문제를 해결한 방법 22 | 23 | 24 | ### 문제를 해결한 코드 25 | ```java 26 | ``` 27 | 28 | 29 | ### 구현 배경 지식 30 | - Math.abs(): 절대값을 구하는 메서드 31 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 41 | --- 42 | 아래의 사이트를 참고해 작성된 글입니다. 43 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj11055.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int N; 8 | vectorv; 9 | 10 | void init() 11 | { 12 | cin >> N; 13 | for (int i = 0; i < N; i++) { 14 | int val; 15 | cin >> val; 16 | v.push_back(val); 17 | } 18 | } 19 | 20 | void solve() 21 | { 22 | vectordp(N); 23 | 24 | for (int i = 0; i < v.size(); i++) 25 | { 26 | int MAX = 0; 27 | 28 | for (int j = 0; j < i; j++) 29 | { 30 | if (v[i] > v[j]) 31 | MAX = max(MAX, dp[j]); 32 | } 33 | dp[i] = (MAX + v[i]); 34 | } 35 | 36 | int answer = 0; 37 | 38 | for (int i = 0; i < N; i++) { 39 | answer = max(answer, dp[i]); 40 | } 41 | cout << answer << endl; 42 | } 43 | 44 | int main() 45 | { 46 | ios_base::sync_with_stdio(0); 47 | cout.tie(0); 48 | cin.tie(0); 49 | 50 | init(); 51 | solve(); 52 | return 0; 53 | } -------------------------------------------------------------------------------- /source/ohhako/coding test/2018_summerCoding3.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 서머코딩/윈터코딩(~2018) 문제 2 | - 숫자 게임 3 | - https://programmers.co.kr/learn/courses/30/lessons/12987 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 입력값: A와 B의 숫자 배열 8 | - 출력값: B가 최대로 이길때 점수 최대값 9 | ### 문제 접근 방법 10 | - 구하고자 하는 값은 순서와 관계가 없다. 11 | - 따라서 비교를 쉽게 하도록 오름차순 정렬한다. 12 | - A의 가장 작은 값부터 B가 이기는 갯수를 카운트 한다. 13 | 14 | ### 접근 방법을 적용한 코드 15 | ```java 16 | import java.util.Arrays; 17 | class Solution { 18 | public int solution(int[] A, int[] B) { 19 | int answer = 0; 20 | int i=0,j=0; 21 | Arrays.sort(A); 22 | Arrays.sort(B); 23 | 24 | while(i=0) 33 | dp[i]=Math.min(dp[i], dp[i-coin[j]]+1); 34 | } 35 | } 36 | if(dp[k]>=99999999) System.out.println("-1"); 37 | else System.out.println(dp[k]); 38 | } 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj18511.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int N, K; 9 | map hash_map; 10 | 11 | void init() 12 | { 13 | cin >> N >> K; 14 | 15 | for (int i = 0; i < K; i++) { 16 | int val; 17 | cin >> val; 18 | hash_map[val] = 1; 19 | } 20 | } 21 | 22 | bool checkNumber(int num) 23 | { 24 | vectorret; 25 | int div = 10; 26 | 27 | while (num != 0) 28 | { 29 | if (hash_map.count(num % 10) == 0) 30 | { 31 | return true; 32 | } 33 | num /= 10; 34 | } 35 | 36 | return false; 37 | } 38 | 39 | int main() 40 | { 41 | ios_base::sync_with_stdio(0); 42 | cout.tie(0); 43 | cin.tie(0); 44 | 45 | init(); 46 | 47 | for (int i = N; i >= 1; i--) { 48 | if (N >= i) 49 | { 50 | if (!checkNumber(i)) { 51 | cout << i << endl; 52 | return 0; 53 | } 54 | } 55 | } 56 | return 0; 57 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1339(단어수학-탐욕법).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int N; 11 | long long answer; 12 | vectorhash_map(101); 13 | 14 | bool comp(int a,int b) { 15 | return a > b ? true : false; 16 | } 17 | 18 | void solve() 19 | { 20 | cin >> N; 21 | 22 | for (int i = 0; i < N; i++) 23 | { 24 | string str; 25 | cin >> str; 26 | 27 | for (int j = str.length() - 1, k = 1; j >= 0; j--, k *= 10) 28 | hash_map[str[j] - 'A'] += k; 29 | } 30 | sort(hash_map.begin(), hash_map.end(),comp); 31 | 32 | for (int i = 0, j = 9; i < hash_map.size() && hash_map[i]; i++, j--) 33 | answer += (j * hash_map[i]); 34 | } 35 | 36 | int main() 37 | { 38 | ios_base::sync_with_stdio(0); 39 | cout.tie(0); 40 | cin.tie(0); 41 | 42 | solve(); 43 | cout << answer << endl; 44 | return 0; 45 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/소수만들기.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | vectorarr; 9 | vectorprimeNums = vector(3001, 1); 10 | vectorcomb; 11 | int answer; 12 | 13 | void makePrimeNums() 14 | { 15 | for (int i = 2; i <= sqrt(3000); i++) 16 | { 17 | for (int j = i * 2; j <= 3000; j += i) 18 | primeNums[j] = 0; 19 | } 20 | } 21 | 22 | void solve(int idx, int cnt) 23 | { 24 | if (cnt >= 3) 25 | { 26 | int SUM = 0; 27 | for (int i = 0; i < comb.size(); i++) SUM += comb[i]; 28 | if (SUM > 1 && primeNums[SUM]) answer++; 29 | return; 30 | } 31 | 32 | for (int i = idx + 1; i < arr.size(); i++) 33 | { 34 | comb.push_back(arr[i]); 35 | solve(i, cnt + 1); 36 | comb.pop_back(); 37 | } 38 | } 39 | 40 | int solution(vector nums) { 41 | arr = nums; 42 | makePrimeNums(); 43 | solve(-1, 0); 44 | return answer; 45 | } 46 | -------------------------------------------------------------------------------- /source/soyeon/[programmers]43105.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | - 정수 삼각형 3 | - https://programmers.co.kr/learn/courses/30/lessons/43105 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 삼각형의 꼭대기에서 바닥까지 이어지는 경로 중, 거쳐간 숫자의 합이 가장 큰 경우를 찾는 문제이다. 8 | - 아래 칸으로 이동할 때는 대각선 방향으로 한 칸 오른쪽 또는 왼쪽으로만 이동 가능하다 9 | 10 | ### 문제 접근 방법 11 | - A[i][j]: i행 j 열의 삼각형까지 경로의 최댓값 12 | 13 | ### 구현 배경 지식 14 | - greedy(?) 15 | 16 | ### 접근 방법을 적용한 코드 17 | ```java 18 | class Solution { 19 | public int solution(int[][] A) { 20 | int n=A.length; 21 | for (int i = 1; i < n; i++) { 22 | for (int j = 0; j <= i; j++) { 23 | if (j == 0) 24 | A[i][j] += A[i - 1][j]; 25 | else if (j == i) 26 | A[i][j] += A[i - 1][j - 1]; 27 | else 28 | A[i][j] += Math.max(A[i - 1][j], A[i - 1][j - 1]); 29 | } 30 | } 31 | int max = A[n - 1][0]; 32 | for (int i = 1; i < n; i++) { 33 | if (max < A[n - 1][i]) 34 | max = A[n - 1][i]; 35 | } 36 | return max; 37 | } 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /source/soyeon/[programmers]43165.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | - 타겟 넘버 3 | - https://programmers.co.kr/learn/courses/30/lessons/43165 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 숫자를 더하거나 빼서 최종 결과가 targetSum과 같은 경우의 수를 구하는 문제 8 | 9 | ### 문제 접근 방법 10 | - 재귀함수 11 | 12 | ### 구현 배경 지식 13 | - 브루트포스 14 | 15 | ### 접근 방법을 적용한 코드 16 | ```java 17 | class Solution { 18 | public static int answer=0; 19 | public int solution(int[] numbers, int target) { 20 | findAll(numbers, target, 1, numbers[0]); 21 | findAll(numbers, target, 1, numbers[0]*(-1)); 22 | return answer; 23 | } 24 | public void findAll(int[] numbers, int target, int nowIndex, int sum) { 25 | if(nowIndex==numbers.length) { 26 | if(target==sum) { 27 | answer++; 28 | } 29 | return; 30 | } 31 | findAll(numbers, target, nowIndex+1, sum+numbers[nowIndex]); 32 | findAll(numbers, target, nowIndex+1, sum-numbers[nowIndex]); 33 | } 34 | } 35 | 36 | ``` 37 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj3040.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | using namespace std; 9 | 10 | vector arr; 11 | 12 | void init() 13 | { 14 | for (int i = 1; i <= 9; i++) 15 | { 16 | int n; 17 | cin >> n; 18 | arr.push_back(n); 19 | } 20 | } 21 | 22 | void solve(int idx, int cnt, vectorparam) 23 | { 24 | if (cnt == 7) { 25 | int SUM = 0; 26 | for (int i = 0; i < param.size(); i++) { 27 | SUM += arr[param[i]]; 28 | } 29 | if (SUM == 100) { 30 | for (int elem : param) { 31 | cout << arr[elem] << endl; 32 | } 33 | } 34 | return; 35 | } 36 | 37 | for (int i = idx + 1; i < arr.size(); i++) { 38 | param.push_back(i); 39 | solve(i, cnt + 1, param); 40 | param.pop_back(); 41 | } 42 | } 43 | 44 | int main() 45 | { 46 | ios_base::sync_with_stdio(0); 47 | cout.tie(0); 48 | cin.tie(0); 49 | 50 | init(); 51 | solve(-1, 0, {}); 52 | return 0; 53 | } -------------------------------------------------------------------------------- /source/kim-dabin/BJ_2156.md: -------------------------------------------------------------------------------- 1 | # [자바/백준] 포도주 시식 2 | 3 | [문제 링크](https://www.acmicpc.net/problem/2156) 4 | 5 | ## 코드 구현 6 | 7 | ```java 8 | import java.io.*; 9 | 10 | public class Main { 11 | public static int dp(int[] a) { 12 | int[] dp = new int[a.length]; 13 | dp[0]=0; 14 | if(a.length>=2) { //N=1 15 | dp[1] = a[1]; 16 | } 17 | if(a.length>=3) { //N=2 18 | dp[2] = a[1]+a[2]; 19 | } 20 | 21 | for(int i=3; i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | typedef long long LL; 11 | 12 | int N, S; 13 | vectorpos; 14 | 15 | void init() 16 | { 17 | cin >> N >> S; 18 | 19 | for (int i = 0; i < N; i++) { 20 | int val; 21 | cin >> val; 22 | pos.push_back(val); 23 | } 24 | } 25 | 26 | int gcd(int a, int b) 27 | { 28 | if (a == 0) 29 | return b; 30 | else 31 | return gcd(b % a, a); 32 | } 33 | 34 | int solve() 35 | { 36 | vectorv; 37 | 38 | for (int i = 0; i < pos.size(); i++) { 39 | v.push_back(abs(pos[i] - S)); 40 | } 41 | 42 | int ans = v[0]; 43 | 44 | for (int i = 0; i < v.size(); i++) { 45 | ans = gcd(ans, v[i]); 46 | } 47 | return ans; 48 | } 49 | 50 | int main() 51 | { 52 | ios_base::sync_with_stdio(0); 53 | cout.tie(0); 54 | cin.tie(0); 55 | 56 | init(); 57 | cout << solve() << endl; 58 | return 0; 59 | } -------------------------------------------------------------------------------- /source/soyeon/[boj]2156.md: -------------------------------------------------------------------------------- 1 | # 백준 문제 2 | - 포도주 시식 3 | - https://www.acmicpc.net/problem/2156 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 연속으로 놓여 있는 3잔을 모두 마실 수는 없다. 8 | 9 | ### 문제 접근 방법 10 | - n번째 잔까지 최대값을 ans[n]에 저장한다. 11 | 12 | ### 구현 배경 지식 13 | - DP 14 | 15 | ### 접근 방법을 적용한 코드 16 | ```java 17 | import java.util.*; 18 | public class Main { 19 | public static void main(String[] args) { 20 | Scanner in=new Scanner(System.in); 21 | int n=in.nextInt(); 22 | int arr[]=new int[n+1]; 23 | int ans[]=new int[n+1]; 24 | for(int i=1;i<=n;i++){ 25 | arr[i]=in.nextInt(); 26 | } 27 | 28 | ans[1]=arr[1]; 29 | 30 | if(n>=2){ 31 | ans[2]=arr[1]+arr[2]; 32 | } 33 | 34 | for(int i=3;i<=n;i++){ 35 | ans[i]=Math.max(ans[i-1], ans[i-2]+arr[i]); 36 | ans[i]=Math.max(ans[i], arr[i]+arr[i-1]+ans[i-3]); 37 | } 38 | 39 | System.out.println(ans[n]); 40 | } 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /source/woodi/201226_boj_2839.md: -------------------------------------------------------------------------------- 1 | # 백준 DP 2 | - 설탕배달 3 | - https://www.acmicpc.net/problem/2839 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 봉지에는 두가지 종류가 있다 : 3kg, 5kg 8 | - 총 배달해야 할 설탕의 양 N kg이 주어졌을 때 9 | - 필요한 최소한의 봉지 개수를 구하시오 10 | 11 | ### 문제 접근 방법 12 | - d[i] : ikg의 설탕을 담기위한 최소한의 봉지 개수 13 | - bottom up 방식으로 구현 14 | ### 구현 배경 지식 15 | - DP 16 | ### 접근 방법을 적용한 코드 17 | ```java 18 | 19 | import java.util.Scanner; 20 | 21 | public class boj_2839_2 { 22 | static int[] d; 23 | public static void main(String[] args) { 24 | Scanner sc = new Scanner(System.in); 25 | int n = sc.nextInt(); 26 | d = new int[n+1]; // nkg을 배달하기까지 최소 이동 횟수 27 | d[3]=1; 28 | if(n>=5) { 29 | d[5]=1; 30 | } 31 | 32 | for(int i=6; i<=n; i++) { 33 | if(d[i-5]>0) { 34 | d[i]=d[i-5]+1; 35 | }else if(d[i-3]>0) { 36 | d[i]=d[i-3]+1; 37 | } 38 | } 39 | 40 | int answer; 41 | if(d[n]==0) { 42 | answer =-1; 43 | }else { 44 | answer = d[n]; 45 | } 46 | System.out.println(answer); 47 | } 48 | } 49 | 50 | ``` 51 | 52 | -------------------------------------------------------------------------------- /source/soyeon/[programmers] 43105.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | 3 | - 정수 삼각형 4 | - https://programmers.co.kr/learn/courses/30/lessons/43105 5 | 6 | ### 문제 이해하기 7 | 삼각형의 꼭대기에서 바닥까지 이어지는 경로 중, 거쳐간 숫자의 합이 가장 큰 경우를 찾는 문제 8 | 9 | ### 문제 접근 방법 10 | 위에서부터 내려오면서 큰 것을 저장하도록 한다. 11 | 12 | ### 구현 배경 지식 13 | dp 14 | 15 | ### 접근 방법을 적용한 코드 16 | ```java 17 | import java.util.*; 18 | class Solution { 19 | public int solution(int[][] triangle) { 20 | int row = triangle.length; 21 | 22 | for (int i = 1; i < row; i++) { 23 | int col = triangle[i].length; 24 | for (int j = 0; j < col; j++) { 25 | if (j == 0) { 26 | triangle[i][j] += triangle[i - 1][j]; 27 | } else if (j == col - 1) { 28 | triangle[i][j] += triangle[i - 1][j - 1]; 29 | } else { 30 | triangle[i][j] += Math.max(triangle[i - 1][j - 1], triangle[i - 1][j]); 31 | } 32 | } 33 | } 34 | 35 | int max = 0; 36 | for (int i = 0; i < triangle[row - 1].length; i++) { 37 | max = Math.max(max, triangle[row - 1][i]); 38 | } 39 | return max; 40 | } 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj9935(문자열폭발-배열).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | string str, target; 9 | char answer[1000001]; 10 | int idx; 11 | 12 | int main() 13 | { 14 | ios_base::sync_with_stdio(0); 15 | cout.tie(0); 16 | cin.tie(0); 17 | 18 | cin >> str >> target; 19 | 20 | for (int i = 0; i < str.length(); i++) 21 | { 22 | answer[idx++] = str[i]; 23 | 24 | if (answer[idx - 1] == target[target.length() - 1]) 25 | { 26 | if (idx < target.length()) 27 | continue; 28 | 29 | bool flag = true; 30 | 31 | for (int j = 0; j < target.length(); j++) 32 | { 33 | if (answer[idx - 1 - j] != target[target.length() - 1 - j]) 34 | { 35 | flag = false; 36 | break; 37 | } 38 | } 39 | 40 | if (flag) 41 | idx -= target.length(); 42 | } 43 | } 44 | 45 | if (idx == 0) { 46 | cout << "FRULA" << endl; 47 | } 48 | else { 49 | for (int i = 0; i < idx; i++) { 50 | cout << answer[i]; 51 | } 52 | cout << endl; 53 | } 54 | return 0; 55 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj14003.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main() 10 | { 11 | ios_base::sync_with_stdio(0); 12 | cin.tie(0); 13 | cout.tie(0); 14 | 15 | int N; 16 | int cnt = 0; 17 | vectorv; 18 | vectorp; 19 | vectorarr; 20 | vector answer; 21 | 22 | v.push_back(-2e9); 23 | 24 | cin >> N; 25 | 26 | for (int i = 0; i < N; i++) 27 | { 28 | int val; 29 | cin >> val; 30 | arr.push_back(val); 31 | 32 | if (v.back() < val) { 33 | v.push_back(val); 34 | p.push_back(++cnt); 35 | } 36 | else { 37 | auto it = lower_bound(v.begin(), v.end(), val); 38 | *it = val; 39 | p.push_back(distance(v.begin(), it)); 40 | } 41 | } 42 | 43 | cout << cnt << endl; 44 | 45 | for (int i = N - 1; i >= 0; i--) { 46 | if (p[i] == cnt) { 47 | answer.push_back(arr[i]); 48 | cnt--; 49 | } 50 | } 51 | 52 | for (int i = answer.size() - 1; i >= 0; i--) { 53 | cout << answer[i] << " "; 54 | } 55 | 56 | return 0; 57 | } -------------------------------------------------------------------------------- /source/lee/200324_hashmap.md: -------------------------------------------------------------------------------- 1 | # Two Sum 2 | https://leetcode.com/problems/two-sum/ 3 | 4 | ## 문제 접근 방법 5 | Map에 key=nums[i], value=i를 저장함 6 | 1. nums를 하나씩 돌면서 target-nums[i]가 map에 저장되어있는지 확인. 7 | 2. 만약 있으면 바로 그 값이 키로 value를 구함. 8 | 3. 없으면 map에 저장 9 | 10 | ### 문제점 11 | 처음에 map에 어떤 값을 key로, 어떤 값을 value로 저장해야했었는지 많이 헷갈렸다. `(k,v) = (idx,nums[idx])`, `(k,v) = (nums[idx], target-nums[idx])`등 저장하는 자료구조를 잘못 선택해서 시간을 많이 낭비했다. 12 | 13 | ## 코드 구현 14 | ```java 15 | class Solution { 16 | public int[] twoSum(int[] nums, int target) { 17 | Map map = new HashMap<>(); 18 | 19 | int[] result = new int[2]; 20 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | string str_num; 11 | int hash_map[10000001]; 12 | int visited[8]; 13 | int answer; 14 | 15 | bool checkPrimeNums(int N) 16 | { 17 | for (int i = 2; i <= sqrt(N); i++) { 18 | if (N % i == 0) return true; 19 | } 20 | return false; 21 | } 22 | 23 | void solve(int cnt, string num) 24 | { 25 | if (cnt >= str_num.length()) 26 | return; 27 | 28 | for (int i = 0; i < str_num.length(); i++) 29 | { 30 | if (visited[i] == 0) 31 | { 32 | visited[i] = 1; 33 | num.push_back(str_num[i]); 34 | if (stoi(num) > 1 && checkPrimeNums(stoi(num)) == 0 && hash_map[stoi(num)] == 0) { 35 | answer++; 36 | hash_map[stoi(num)] = 1; 37 | } 38 | solve(cnt + 1, num); 39 | visited[i] = 0; 40 | num.pop_back(); 41 | } 42 | } 43 | } 44 | 45 | int solution(string numbers) { 46 | str_num = numbers; 47 | solve(0, ""); 48 | return answer; 49 | } 50 | 51 | int main() 52 | { 53 | solution("011"); 54 | return 0; 55 | } -------------------------------------------------------------------------------- /source/ohhako/boj/bj_2309.java: -------------------------------------------------------------------------------- 1 | // https://www.acmicpc.net/status?user_id=hrkeon0503&problem_id=2309&from_mine=1 2 | import java.util.*; 3 | public class Main{ 4 | public static void main(String[] args){ 5 | //입력을 모두 더한 값에서 두명을 뺏을때 100이어야 함. 6 | int[] dwarfs = new int[9]; 7 | Scanner sc = new Scanner(System.in); 8 | int total = 0; 9 | for(int i=0 ; i st = new Stack<>(); 25 | int[] answer = new int[prices.length]; 26 | 27 | for (int i = 0; i < prices.length; i++) { 28 | while (!st.empty() && prices[i] < prices[st.peek()]) { 29 | int index = st.pop(); 30 | answer[index] = i - index; 31 | } 32 | st.push(i); 33 | } 34 | while (!st.empty()) { 35 | int index = st.pop(); 36 | answer[index] = (prices.length - 1) - index; 37 | } 38 | 39 | return answer; 40 | } 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /source/lee/team/20200607_숫자게임.md: -------------------------------------------------------------------------------- 1 | # 로또 2 | 3 | https://programmers.co.kr/learn/courses/30/lessons/12987 4 | 5 | ## 문제 접근 방법 6 | 7 | - 맨 처음 문제 접근하지 못한 이유: 문제의 본질은 A, B를 정렬한 후 큰 숫자부터 비교하는 것이지만, A팀의 출전 순서에만 집착하고 있었다. 답지 찾아보고 이해함 8 | - 정렬 후 비교 9 | 10 | 1. A, B팀 각 배열의 인덱스를 만들고 끝에서부터 비교 11 | 2. b팀의 숫자가 크면 점수`count` 획득하고 두 인덱스 전부 감소. b팀의 숫자가 작으면 그 판은 졌기 때문에(코드에는 쓰여있지 않지만 b팀에서 가장 작은 숫자를 냈다고 가정) A의 인덱스만 1 감소 12 | 3. idxA<0이 되는 순간 n번의 비교가 다 끝났기 때문에 최종 `count`를 리턴함 13 | 14 | ### 코드 15 | 16 | ```java 17 | import java.util.Arrays; 18 | 19 | class Solution { 20 | public int solution(int[] A, int[] B) { 21 | Arrays.sort(A); 22 | Arrays.sort(B); 23 | 24 | int idxA=A.length-1; 25 | int idxB=idxA; 26 | 27 | int count=0; 28 | while(idxA>=0){ 29 | int curA=A[idxA]; 30 | int curB=B[idxB]; 31 | if (curA h) { 41 | low = mid; 42 | } else { 43 | high = mid; 44 | } 45 | } 46 | System.out.println(mid); 47 | } 48 | } 49 | ``` 50 | -------------------------------------------------------------------------------- /source/ohhako/200607_dp.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 DP 문제 2 | - 정수 삼각형 3 | - https://programmers.co.kr/learn/courses/30/lessons/43105 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 입력값: 정삼각형 구조의 2차원 배열 8 | - 출력값: 꼭대기에서 대각선으로 가장 아래까지 내려가는 합의 최대값 9 | ### 문제 접근 방법 10 | - 배열 요소를 차례대로 순회한다. 11 | - 현재 위치는 위에서 내려온 값에 의해 최종 결정된다. 12 | - 현재 위치가 갖는 값은 지금까지 지나온 최대 경로 합을 의미한다. 13 | 14 | 15 | ### 접근 방법을 적용한 코드 16 | ```java 17 | import java.lang.Math; 18 | class Solution { 19 | public int solution(int[][] triangle) { 20 | int answer = 0; 21 | 22 | for(int i=1 ; i pq의 첫 번째 원소=최소 스코빌지수 6 | 2. 문제 조건대로 최소 스코빌 지수, 두 번째로 작은 스코빌 지수로 새 스코빌 지수를 구한 후 다시 pq에 넣음. 7 | 3. pq의 헤드값이 K 이상이면 모든 음식의 스코빌 지수가 K이상이라는 뜻이므로 그동안의 섞은 카운트를 반환 8 | 4. while루프가 끝날때까지 반환하지 못했다는것은 모든 음식의 스코빌 지수를 새로 계산해도 K보다 작다는 의미이기 때문에 -1 반환 9 | 10 | 11 | ## 코드 구현 12 | ```java 13 | import java.util.*; 14 | class Solution { 15 | public int solution(int[] scoville, int K) { 16 | PriorityQueue queue = new PriorityQueue<>(scoville.length); 17 | for (int i: scoville) queue.add(i); 18 | int count=0; 19 | while (queue.size()>1) { 20 | count++; 21 | int sco1 = queue.poll(); 22 | int sco2 = queue.poll(); 23 | int newSco = sco1 + 2*sco2; 24 | queue.add(newSco); 25 | if (queue.peek()>=K) return count; 26 | 27 | } 28 | 29 | 30 | return -1; 31 | } 32 | } 33 | 34 | ``` 35 | 36 | ### Time complexity 37 | O(n) n=scoville.length 38 | 39 | ### Space complexity 40 | O(n) n=scoville.length 41 | -------------------------------------------------------------------------------- /source/ohhako/boj/bj_11052.md: -------------------------------------------------------------------------------- 1 | <<<<<<< HEAD:source/ohhako/boj/200319_dp.md 2 | # 백준 동적 프로그래밍(DP) 문제 3 | 4 | # 프로그래머스 스택/큐 문제 5 | ======= 6 | # 백준 DP 문제 7 | >>>>>>> ohhako:source/ohhako/boj/bj_11052.md 8 | 9 | - 카드 구매하기 10 | - https://www.acmicpc.net/problem/11052 11 | 12 | ### 문제와 주어진 조건 이해하기 13 | 14 | - i를 합쳐서 N이 되도록 Pi를 구성하여 최대값이 나오도록 해라. 15 | 16 | ### 문제 접근 방법 17 | 18 | - P(n) = P(i) + P(i+1) 19 | - P(n) 를 최대값으로 만들려면 구성하는 P들도 최대값으로 이루어져 있어야 한다. 20 | - P(i)의 인덱스를 1부터 N까지 값을 입력받으면서 해당 인덱스 미만의 P들의 합보다 작으면 값을 바꾸어 준다. 결과, 모든 P(i)는 최대값의 조합으로 구성되어 있다. 21 | 22 | ### 구현 배경 지식 23 | 24 | - dp 기본개념 25 | 26 | ### 접근 방법을 적용한 코드 27 | 28 | ```java 29 | import java.util.Scanner; 30 | import java.lang.Math; 31 | public class Main{ 32 | public static void main(String[] args){ 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | int[] p = new int[n+1]; 36 | 37 | for(int i=1 ; i<=n ; i++){ 38 | p[i] = sc.nextInt(); 39 | for(int j =1 ; j<=i/2 ; j++){ 40 | p[i] = Math.max(p[i],p[j]+p[i-j]); 41 | } 42 | } 43 | System.out.println(p[n]); 44 | } 45 | } 46 | ``` 47 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj13023.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | typedef pair Pair; 12 | 13 | int N, M; 14 | vectorGP[2001]; 15 | int visited[2001]; 16 | 17 | void init() 18 | { 19 | cin >> N >> M; 20 | 21 | for (int i = 0; i < M; i++) 22 | { 23 | int a, b; 24 | cin >> a >> b; 25 | GP[a].push_back(Pair(b, 1)); 26 | GP[b].push_back(Pair(a, 1)); 27 | } 28 | } 29 | 30 | bool dfs(int idx, int cnt) 31 | { 32 | if (cnt >= 4) 33 | { 34 | return true; 35 | } 36 | 37 | visited[idx] = 1; 38 | 39 | for (auto elem : GP[idx]) 40 | { 41 | if (!visited[elem.first]) 42 | { 43 | if (dfs(elem.first, cnt + 1)) 44 | return true; 45 | } 46 | } 47 | visited[idx] = 0; 48 | return false; 49 | } 50 | 51 | int main() 52 | { 53 | ios_base::sync_with_stdio(false); 54 | cout.tie(0); 55 | cin.tie(0); 56 | init(); 57 | 58 | for (int i = 0; i < N; i++) 59 | { 60 | if (dfs(i, 0)) { 61 | cout << 1 << endl; 62 | return 0; 63 | } 64 | } 65 | cout << 0 << endl; 66 | return 0; 67 | } -------------------------------------------------------------------------------- /source/soyeon/[programmers]12981.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 스택/큐 문제 2 | - 영어 끝말잇기 3 | - https://programmers.co.kr/learn/courses/30/lessons/12981 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 이전 단어의 끝 char == 다음 단어의 첫 char인지 확인 8 | - 이전에 나왔던 단어인지 확인 9 | 10 | ### 문제 접근 방법 11 | 12 | ### 구현 배경 지식 13 | 14 | ### 접근 방법을 적용한 코드 15 | ```java 16 | class Solution { 17 | public int[] solution(int n, String[] words) { 18 | int[] answer = new int[2]; 19 | 20 | HashSet set = new HashSet(); 21 | 22 | String before = words[0]; 23 | set.add(words[0]); 24 | 25 | for (int i = 1; i < words.length; i++) { 26 | if (set.contains(words[i])) { 27 | return setAnswer(i, n); 28 | } 29 | 30 | if (before.charAt(before.length() - 1) != words[i].charAt(0)) { 31 | return setAnswer(i, n); 32 | } 33 | 34 | set.add(words[i]); 35 | before = words[i]; 36 | } 37 | 38 | return answer; 39 | } 40 | public int[] setAnswer(int index, int n) { 41 | int answer[] = new int[2]; 42 | answer[0] = (index + 1) % n; 43 | 44 | if (answer[0] == 0) { 45 | answer[0] = n; 46 | } else { 47 | answer[1] = 1; 48 | } 49 | 50 | answer[1] += (index + 1) / n; 51 | return answer; 52 | } 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /source/woodi/201023_Programmers_42895.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 DP 문제 2 | - N으로 표현 3 | - https://programmers.co.kr/learn/courses/30/lessons/42895 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 숫자 N과 number가 주어질 때, N과 사칙연산만 사용해서 number를 표현 할 수 있는 방법 중 N 사용횟수의 최솟값을 구하시오. 8 | 9 | ### 문제 접근 방법 10 | - 11 | ### 구현 배경 지식 12 | - DP 13 | ### 접근 방법을 적용한 코드 14 | ```java 15 | import java.util.*; 16 | class Solution { 17 | static int answer =-1; 18 | public int solution(int N, int number) { 19 | dfs(N, number, 0,0); 20 | return answer; 21 | } 22 | static void dfs(int N, int number, int cnt, int prev){ 23 | int nn = N; 24 | if(cnt>8){ 25 | answer = -1; 26 | return; 27 | } 28 | if(number == prev){ 29 | if(answer ==-1 || answer>cnt){ 30 | answer = cnt; 31 | return; 32 | } 33 | } 34 | for(int i=0; i<8-cnt; i++){ 35 | dfs(N, number, cnt+i+1, prev-nn); 36 | dfs(N, number, cnt+i+1, prev+nn); 37 | dfs(N, number, cnt+i+1, prev*nn); 38 | dfs(N, number, cnt+i+1, prev/nn); 39 | nn = nn*10+N; 40 | } 41 | } 42 | } 43 | ``` 44 | 45 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj9455.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int M, N; 13 | int board[101][101]; 14 | int answer; 15 | 16 | void init() 17 | { 18 | cin >> M >> N; 19 | answer = 0; 20 | 21 | for (int i = 1; i <= M; i++) 22 | { 23 | for (int j = 1; j <= N; j++) 24 | { 25 | cin >> board[i][j]; 26 | } 27 | } 28 | } 29 | 30 | void boxMoving() 31 | { 32 | for (int i = M; i >= 1; i--) 33 | { 34 | for (int j = 1; j <= N; j++) 35 | { 36 | if (board[i][j]) 37 | { 38 | int cnt = 0, cur_pos = i; 39 | 40 | while (cur_pos + 1 <= M && board[cur_pos + 1][j] == 0) 41 | { 42 | cnt++; 43 | board[++cur_pos][j] = 1; 44 | board[cur_pos - 1][j] = 0; 45 | } 46 | answer += cnt; 47 | } 48 | } 49 | } 50 | } 51 | 52 | int main() 53 | { 54 | ios_base::sync_with_stdio(0); 55 | cout.tie(0); 56 | cin.tie(0); 57 | 58 | int test; 59 | cin >> test; 60 | 61 | for (int t = 0; t < test; t++) 62 | { 63 | init(); 64 | boxMoving(); 65 | cout << answer << endl; 66 | } 67 | return 0; 68 | } -------------------------------------------------------------------------------- /source/soyeon/[programmers]12987.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | - 숫자 게임 3 | - https://programmers.co.kr/learn/courses/30/lessons/12987 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - B가 A를 이긴 횟수를 세는 문제이다. 8 | 9 | ### 문제 접근 방법 10 | - 두 배열을 정렬하여 이긴 횟수를 센다. 11 | 12 | ### 구현 배경 지식 13 | 14 | ### 접근 방법을 적용한 코드 15 | ```java 16 | class Solution { 17 | public int solution(int[] A, int[] B) { 18 | int index = 0; 19 | Arrays.parallelSort(A); 20 | Arrays.parallelSort(B); 21 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | int N, M; 9 | char board[51][51]; 10 | int answer = 2e9; 11 | 12 | void init() 13 | { 14 | cin >> N >> M; 15 | 16 | for (int i = 1; i <= N; i++) 17 | { 18 | string str; 19 | cin >> str; 20 | for (int j = 1; j <= M; j++) { 21 | board[i][j] = str[j - 1]; 22 | } 23 | } 24 | } 25 | 26 | void solve() 27 | { 28 | int cnt1 = 0; 29 | 30 | for (int i = 1; i <= N; i++) 31 | { 32 | bool flag = false; 33 | 34 | for (int j = 1; j <= M; j++) 35 | { 36 | if (board[i][j] == 'X') { 37 | flag = true; 38 | break; 39 | } 40 | } 41 | if (!flag) cnt1++; 42 | } 43 | 44 | int cnt2 = 0; 45 | 46 | for (int i = 1; i <= M; i++) 47 | { 48 | bool flag = false; 49 | 50 | for (int j = 1; j <= N; j++) 51 | { 52 | if (board[j][i] == 'X') { 53 | flag = true; 54 | break; 55 | } 56 | } 57 | if (!flag)cnt2++; 58 | } 59 | answer = max(cnt1, cnt2); 60 | } 61 | 62 | int main() 63 | { 64 | ios_base::sync_with_stdio(0); 65 | cout.tie(0); 66 | cin.tie(0); 67 | 68 | init(); 69 | solve(); 70 | cout << answer << endl; 71 | return 0; 72 | } -------------------------------------------------------------------------------- /source/soyeon/[boj]11403.md: -------------------------------------------------------------------------------- 1 | # 백준 문제 2 | - 경로 찾기 3 | - https://www.acmicpc.net/problem/11403 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 모든 정점 (i, j)에 대해서, i에서 j로 가는 경로가 있는지 없는지 구하는 문제이다. 8 | 9 | ### 문제 접근 방법 10 | - 다익스트라 알고리즘을 모든 점에 대해 구하여 경로가 없는 길을 찾아낸다. 11 | 12 | ### 구현 배경 지식 13 | - 다익스트라 알고리즘 14 | 15 | ### 접근 방법을 적용한 코드 16 | ```java 17 | import java.util.*; 18 | public class Main { 19 | 20 | public static void main(String[] args) { 21 | Scanner in=new Scanner(System.in); 22 | 23 | int n=in.nextInt(); 24 | int dist[][]=new int[n+1][n+1]; 25 | 26 | for(int i=1;i<=n;i++) 27 | for(int j=1;j<=n;j++) 28 | dist[i][j]=9999; 29 | 30 | 31 | for(int i=1;i<=n;i++) 32 | for(int j=1;j<=n;j++){ 33 | int l=in.nextInt(); 34 | if(l==1) dist[i][j]=1; 35 | } 36 | 37 | 38 | for(int k=1; k<=n; k++) 39 | for(int i=1; i<=n; i++) 40 | for(int j=1; j<=n; j++) 41 | dist[i][j]=Math.min(dist[i][j], dist[i][k]+dist[k][j]); 42 | 43 | for(int i=1;i<=n;i++){ 44 | for(int j=1;j<=n;j++){ 45 | if(dist[i][j]==9999) System.out.print("0 "); 46 | else System.out.print("1 "); 47 | } 48 | System.out.println(); 49 | } 50 | 51 | } 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /source/soyeon/[programmers] 17681.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | 3 | - 비밀지도 4 | - https://programmers.co.kr/learn/courses/30/lessons/17681 5 | 6 | ### 문제 이해하기 7 | 8 | ### 문제 접근 방법 9 | 각 수를 이진수로 바꾼다 10 | 11 | ### 구현 배경 지식 12 | Integer.toBinaryString 사용 13 | 14 | ### 접근 방법을 적용한 코드 15 | ```java 16 | class Solution { 17 | public String[] solution(int n, int[] arr1, int[] arr2) { 18 | String[] answer = new String[n]; 19 | 20 | for (int i = 0; i < n; i++) { 21 | StringBuilder sb = new StringBuilder(); 22 | String map1 = Integer.toBinaryString(arr1[i]); 23 | String map2 = Integer.toBinaryString(arr2[i]); 24 | int length1 = map1.length(); 25 | int length2 = map2.length(); 26 | 27 | if (map1.length() < n) { 28 | for (int j = 0; j < n - length1; j++) { 29 | map1 = "0" + map1; 30 | } 31 | } 32 | if (map2.length() < n) { 33 | for (int j = 0; j < n - length2; j++) { 34 | map2 = "0" + map2; 35 | } 36 | } 37 | 38 | for (int j = 0; j < n; j++) { 39 | if (map1.charAt(j) == '1' || map2.charAt(j) == '1') { 40 | sb.append('#'); 41 | } else { 42 | sb.append(' '); 43 | } 44 | } 45 | answer[i] = sb.toString(); 46 | 47 | } 48 | 49 | return answer; 50 | } 51 | } 52 | ``` 53 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1167.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | typedef pair Pair; 10 | int N; 11 | vectorGP[100001]; 12 | int visited[100001]; 13 | int MAX_V, MAX_LEN; 14 | 15 | void init() 16 | { 17 | cin >> N; 18 | 19 | for (int i = 1; i <= N; i++) 20 | { 21 | vectorv; 22 | int cnt = 0; 23 | 24 | while (++cnt) 25 | { 26 | int val; 27 | cin >> val; 28 | if (val == -1)break; 29 | else { 30 | v.push_back(val); 31 | } 32 | } 33 | for (int j = 1; j < v.size(); j += 2) { 34 | GP[v[0]].push_back(Pair(v[j], v[j + 1])); 35 | } 36 | } 37 | } 38 | 39 | void dfs(int v, int len) 40 | { 41 | visited[v] = 1; 42 | 43 | if (len > MAX_LEN) { 44 | MAX_LEN = len; 45 | MAX_V = v; 46 | } 47 | 48 | for (auto elem : GP[v]) 49 | { 50 | if (visited[elem.first] == 0) { 51 | dfs(elem.first, len + elem.second); 52 | } 53 | } 54 | } 55 | 56 | int main() { 57 | ios_base::sync_with_stdio(0); 58 | cout.tie(0); 59 | cin.tie(0); 60 | 61 | init(); 62 | dfs(1, 0); 63 | memset(visited, 0, sizeof(visited)); 64 | dfs(MAX_V, 0); 65 | cout << MAX_LEN << endl; 66 | return 0; 67 | } -------------------------------------------------------------------------------- /source/ohhako/coding test/kakao/자물쇠와열쇠.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Solution { 3 | public int[][] rotation(int[][] key){ 4 | int m = key.length; 5 | int[][] newKey = new int[m][m]; 6 | for(int i=0 ; i map = new HashMap<>(); 15 | for (String word: magazine) { 16 | if (map.containsKey(word)) map.replace(word, map.get(word)+1); 17 | else map.put(word,1); 18 | } 19 | 20 | for (String word: note) { 21 | if (!map.containsKey(word)) { 22 | System.out.println("No"); 23 | return; 24 | } else { 25 | if (map.get(word)==1) map.remove(word); 26 | else map.replace(word, map.get(word)-1); 27 | } 28 | } 29 | 30 | System.out.println("Yes"); 31 | } 32 | } 33 | ``` 34 | 35 | ### Time complexity 36 | O(n+m) n=note.length, m=magazine.length 37 | 38 | ### Space complexity 39 | O(n+m) n=note.length, m=magazine.length 40 | -------------------------------------------------------------------------------- /source/ohhako/boj/bj_1149.java: -------------------------------------------------------------------------------- 1 | import java.io.InputStreamReader; 2 | import java.io.IOException; 3 | import java.io.BufferedReader; 4 | import java.util.Scanner; 5 | 6 | import java.lang.Math; 7 | 8 | public class Main{ 9 | public static void solution(int n,int[][] rgb){ 10 | for(int i=1 ; i 17 | 18 | ### 접근 방법을 적용한 코드 19 | 20 | ```java 21 | import java.util.Scanner; 22 | 23 | public class Main{ 24 | public static void main(String[] args){ 25 | Scanner sc = new Scanner(System.in); 26 | int t = sc.nextInt(); 27 | 28 | for (int i = 0; i < t; i++) { 29 | int n = sc.nextInt(); 30 | if (n % 3 != 0) { 31 | System.out.println(0); 32 | continue; 33 | } 34 | int[] dp = new int[n + 1]; 35 | int[] newTile = new int[n + 1]; 36 | 37 | dp[3] = 3; 38 | newTile[3] = 4; 39 | for (int j=6; j<=n; j+=3) { 40 | newTile[j] = (j/3)*2; 41 | dp[j] = (dp[j-3]*3 + newTile[j])%1000000007; 42 | 43 | for(int k=j-6 ; k >0 ; k-=3) { 44 | dp[j] = (dp[j]+ dp[k]*newTile[j-k])%1000000007; 45 | } 46 | } 47 | System.out.println(dp[n]); 48 | } 49 | } 50 | } 51 | ``` 52 | 53 | ### 해결하지 못한 이유 54 | 55 | ### 문제를 해결한 코드 56 | 57 | ```java 58 | 59 | ``` 60 | 61 | ### 문제를 해결한 방법 62 | 63 | --- 64 | 65 | 아래의 사이트를 참고해 작성된 글입니다. 66 | -------------------------------------------------------------------------------- /source/lukas/18032020_CaesarCipher.md: -------------------------------------------------------------------------------- 1 | 프로그래머스 문제 2 | ================= 3 | 4 | - 시저암호 5 | - https://programmers.co.kr/learn/courses/30/lessons/12926 6 | 7 | ### 풀이 방법 8 | 9 | #### 문제 접근 방법 10 | 11 | - Caesar Cipher 12 | 13 | #### 접근 방법을 적용한 코드 14 | 15 | ```java 16 | class Solution { 17 | public String solution(String s, int n) { 18 | String answer = ""; 19 | for (char ch : s.toCharArray()) { 20 | if (Character.isLetter(ch)) { 21 | if (Character.isUpperCase(ch)) { 22 | answer += (char) ((ch + n - 'A') % 26 + 'A'); 23 | } else { 24 | answer += (char) ((ch + n - 'a') % 26 + 'a'); 25 | } 26 | } 27 | else { 28 | answer += " "; 29 | } 30 | } 31 | return answer; 32 | } 33 | } 34 | 35 | ``` 36 | 37 | ```haskell 38 | import Data.Char 39 | 40 | caesar :: Int -> Char -> Char 41 | caesar k c | isAsciiUpper c = chr ((ord c + k - ord 'A')`mod` 26 + ord 'A') 42 | | isAsciiLower c = chr ((ord c + k - ord 'a')`mod` 26 + ord 'a') 43 | | otherwise = c 44 | 45 | 46 | garble :: String -> String 47 | garble xs = [caesar 2 x | x <- xs] 48 | 49 | ungarble :: String -> String 50 | ungarble xs = [caesar (-2) x | x <- xs] 51 | -- caeasar 24 52 | ``` 53 | -------------------------------------------------------------------------------- /source/soyeon/[programmers] 42895.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | 3 | - N으로 표현 4 | - https://programmers.co.kr/learn/courses/30/lessons/42895 5 | 6 | ### 문제 이해하기 7 | N과 사칙연산만 사용해서 표현 할 수 있는 방법 중 N 사용횟수의 최솟값을 return 하는 문제이다 8 | 9 | ### 문제 접근 방법 10 | 최솟값이 8보다 크면 -1을 return 조건이 있으므로 모든 경우를 해본다. 11 | 12 | ### 구현 배경 지식 13 | dfs 14 | 15 | ### 문제를 해결한 코드 16 | ```java 17 | class Solution { 18 | public static int answer = 9; 19 | 20 | public int solution(int N, int number) { 21 | dfs(0, 0, N, number); 22 | return answer > 8 ? -1 : answer; 23 | } 24 | 25 | public void dfs(int cnt, int number, int N, int target) { 26 | if (cnt > 8) { 27 | return; 28 | } 29 | 30 | if (number == target) { 31 | answer = Math.min(answer, cnt); 32 | return; 33 | } 34 | 35 | for (int i = 1; i <= 8 - cnt; i++) { 36 | dfs(cnt + i, number + getNum(i, N), N, target); 37 | dfs(cnt + i, number - getNum(i, N), N, target); 38 | dfs(cnt + i, number / getNum(i, N), N, target); 39 | dfs(cnt + i, number * getNum(i, N), N, target); 40 | } 41 | } 42 | 43 | public int getNum(int digit, int N) { 44 | int result = 0; 45 | for (int i = 0; i < digit; i++) { 46 | result += Math.pow(10, i) * N; 47 | } 48 | return result; 49 | } 50 | } 51 | ``` 52 | 53 | ### 문제를 해결한 방법 54 | * [참고](https://zin0-0.tistory.com/82) 55 | 56 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj5567.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | typedef pair Pair; 12 | 13 | int N, M; 14 | vectorGP[501]; 15 | int visited[501]; 16 | int step[501]; 17 | int answer; 18 | 19 | void init() 20 | { 21 | cin >> N >> M; 22 | 23 | for (int i = 0; i < M; i++) 24 | { 25 | int a, b; 26 | cin >> a >> b; 27 | GP[a].push_back(Pair(b, 1)); 28 | GP[b].push_back(Pair(a, 1)); 29 | } 30 | } 31 | 32 | int bfs() 33 | { 34 | queueq; 35 | q.push(1); 36 | visited[1] = 1; 37 | 38 | while (q.empty() != true) 39 | { 40 | int pos = q.front(); 41 | q.pop(); 42 | 43 | for (auto elem : GP[pos]) 44 | { 45 | if (visited[elem.first] == 0) 46 | { 47 | visited[elem.first] = 1; 48 | q.push(elem.first); 49 | step[elem.first] = step[pos] + 1; 50 | } 51 | } 52 | } 53 | 54 | int ret = 0; 55 | 56 | for (int i = 0; i < 501; i++) 57 | { 58 | if (step[i] == 1 || step[i] == 2) 59 | { 60 | ret++; 61 | } 62 | } 63 | return ret; 64 | } 65 | 66 | int main() 67 | { 68 | ios_base::sync_with_stdio(0); 69 | cout.tie(0); 70 | cin.tie(0); 71 | 72 | init(); 73 | cout << bfs() << endl; 74 | return 0; 75 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj2110.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int N, C; 13 | vectorhome_pos; 14 | int answer; 15 | 16 | void init() 17 | { 18 | cin >> N >> C; 19 | 20 | for (int i = 0; i < N; i++) 21 | { 22 | int val; 23 | cin >> val; 24 | home_pos.push_back(val); 25 | } 26 | sort(home_pos.begin(), home_pos.end()); 27 | } 28 | 29 | bool check(int limit) 30 | { 31 | int cnt = 1; 32 | 33 | for (int i = 1, value = home_pos[0]; i < N; i++) 34 | { 35 | if (value + limit <= home_pos[i]) 36 | { 37 | value = home_pos[i]; 38 | cnt++; 39 | } 40 | } 41 | 42 | return cnt >= C ? true : false; 43 | } 44 | 45 | void binary_search() 46 | { 47 | int left = 1, right = home_pos[home_pos.size() - 1] - home_pos[0]; 48 | 49 | while (left <= right) 50 | { 51 | int mid = (left + right) / 2; 52 | 53 | if (check(mid)) { 54 | left = mid + 1; 55 | answer = mid; 56 | } 57 | else { 58 | right = mid - 1; 59 | } 60 | } 61 | } 62 | 63 | int main() 64 | { 65 | ios_base::sync_with_stdio(0); 66 | cout.tie(0); 67 | cin.tie(0); 68 | 69 | init(); 70 | binary_search(); 71 | cout << answer << endl; 72 | return 0; 73 | } -------------------------------------------------------------------------------- /source/ohhako/200526_영어끝말잇기.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 Summer/Winter Coding 2018 문제 2 | 3 | - 영어 끝말잇기 4 | - https://programmers.co.kr/learn/courses/30/lessons/12981?language=java 5 | 6 | ## 풀이 방법 7 | 8 | ### 문제 이해하기 9 | 10 | - 입력값: 사람 수 n, 끝말잇기 단어 배열 11 | - 출력값: 탈락한 사람의 번호와 진행중 탈락한 단어의 순서 12 | 13 | ### 문제 접근 방법 14 | 15 | - HashMap 자료구조로 중복 체크 16 | - 조건일치 17 | - 중복x 18 | - 단어 맨앞 문자가 앞사람의 끝 문자와 일치 19 | - 한 문자 허용금지 20 | 21 | ### 접근 방법을 적용한 코드 22 | 23 | ```java 24 | import java.util.HashMap; 25 | class Solution { 26 | public int[] solution(int n, String[] words) { 27 | HashMap words_hm = new HashMap<>(); 28 | int[] answer = new int[2]; 29 | char lastLetter = words[0].charAt(0); 30 | 31 | for(int i=0 ; i=2 || lastLetter!= w.charAt(0)){ 35 | answer[1] = (i/n)+1; 36 | answer[0] = (i%n)+1; 37 | break; 38 | } 39 | lastLetter = w.charAt(w.length()-1); 40 | } 41 | System.out.println(answer[0] + " "+answer[1]); 42 | return answer; 43 | } 44 | } 45 | ``` 46 | 47 | 52 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1991.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | map>tree; 12 | int N; 13 | 14 | void init() 15 | { 16 | cin >> N; 17 | 18 | for (int i = 1; i <= N; i++) 19 | { 20 | char a, b, c; 21 | cin >> a >> b >> c; 22 | tree[a] = make_pair(b, c); 23 | } 24 | } 25 | 26 | void PreOrderTraversal(char ch) 27 | { 28 | if (ch == '.') 29 | return; 30 | 31 | cout << ch; 32 | PreOrderTraversal(tree[ch].first); 33 | PreOrderTraversal(tree[ch].second); 34 | } 35 | 36 | void InOrderTraversal(char ch) 37 | { 38 | if (ch == '.') 39 | return; 40 | 41 | InOrderTraversal(tree[ch].first); 42 | cout << ch; 43 | InOrderTraversal(tree[ch].second); 44 | } 45 | 46 | void PostOrderTraversal(char ch) 47 | { 48 | if (ch == '.') 49 | return; 50 | 51 | PostOrderTraversal(tree[ch].first); 52 | PostOrderTraversal(tree[ch].second); 53 | cout << ch; 54 | } 55 | 56 | int main() 57 | { 58 | ios_base::sync_with_stdio(0); 59 | cout.tie(0); 60 | cin.tie(0); 61 | 62 | init(); 63 | PreOrderTraversal('A'); 64 | cout << endl; 65 | InOrderTraversal('A'); 66 | cout << endl; 67 | PostOrderTraversal('A'); 68 | cout << endl; 69 | return 0; 70 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj4195.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | int parent[200001]; 12 | int cost[200001]; 13 | int F; 14 | 15 | int find(int idx) 16 | { 17 | if (parent[idx] == idx) return parent[idx]; 18 | return find(parent[idx]); 19 | } 20 | 21 | int merge(int idx1, int idx2) 22 | { 23 | int p1 = find(idx1); 24 | int p2 = find(idx2); 25 | 26 | if (p1 != p2) 27 | { 28 | cost[p1] += cost[p2]; 29 | parent[p2] = parent[p1]; 30 | } 31 | return cost[p1]; 32 | } 33 | 34 | void init() 35 | { 36 | cin >> F; 37 | 38 | for (int i = 1; i <= 2 * F; i++) { 39 | parent[i] = i; 40 | cost[i] = 1; 41 | } 42 | } 43 | 44 | int main() 45 | { 46 | ios_base::sync_with_stdio(0); 47 | cout.tie(0); 48 | cin.tie(0); 49 | 50 | int test; 51 | cin >> test; 52 | 53 | for (int t = 0; t < test; t++) 54 | { 55 | map hash_map; 56 | 57 | init(); 58 | 59 | for (int i = 0, number = 0; i < F; i++) 60 | { 61 | string a, b; 62 | cin >> a >> b; 63 | 64 | if (hash_map[a] == 0) hash_map[a] = ++number; 65 | if (hash_map[b] == 0) hash_map[b] = ++number; 66 | cout << merge(hash_map[a], hash_map[b]) << "\n"; 67 | } 68 | } 69 | return 0; 70 | } -------------------------------------------------------------------------------- /source/lukas/26032020_PipeStack.md: -------------------------------------------------------------------------------- 1 | 프로그래머스 스택/큐 문제 2 | ========================= 3 | 4 | - 쇠막대 5 | - https://programmers.co.kr/learn/courses/30/lessons/42585 6 | 7 | ### 풀이 방법 8 | 9 | #### 문제 접근 방법 10 | 11 | - 왼쪽 괄호를 세어가며 오른쪽 괄호가 나올 때 마다 계산 12 | - increment 만으로도 가능하나 Stack으로도 구현 할 수 있음 13 | - 레이저일 경우 그 전 왼쪽 괄호의 수 만큼 (=쇠 막대기 수 만큼)의 값을 잘린 조각 들의 수에 포함 14 | - 쇠 막대기일 경우 한 쇠막대기의 총 잘린 조각 = 레이저의 수 + 1 이므로 +1 씩 추가 15 | 16 | #### 접근 방법을 적용한 코드 17 | 18 | ```java 19 | import java.util.Stack; 20 | 21 | class Solution { 22 | public static int solution(String arrangement) { 23 | int splitted = 0; 24 | 25 | Stack st = new Stack<>(); 26 | 27 | for(int i = 0; i < arrangement.length(); i++) { 28 | char c = arrangement.charAt(i); 29 | if(c == '(') { 30 | st.push(c); 31 | }else { 32 | if(arrangement.charAt(i-1) == '(') { // if a laser 33 | st.pop(); 34 | splitted += st.size(); // applys a laser-splitting to every pipe 35 | 36 | } else { // if the pipe's right-end 37 | st.pop(); 38 | splitted += 1; // num of the splitted = num of lasers to the pipe + 1 39 | } 40 | } 41 | } 42 | return splitted; 43 | } 44 | } 45 | ``` 46 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj16637.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int N; 13 | char op[20]; 14 | int answer = -2e9; 15 | 16 | void init() 17 | { 18 | cin >> N; 19 | string str; 20 | cin >> str; 21 | for (int i = 1; i <= N; i++) 22 | op[i] = str[i - 1]; 23 | } 24 | 25 | int calc(int left, char op, int right) 26 | { 27 | switch (op) 28 | { 29 | case '+': 30 | return left + right; 31 | case '-': 32 | return left - right; 33 | case '*': 34 | return left * right; 35 | } 36 | } 37 | 38 | void dfs(int idx, int sum) 39 | { 40 | if (idx >= N) 41 | { 42 | answer = max(answer, sum); 43 | return; 44 | } 45 | 46 | if (idx + 2 <= N) 47 | { 48 | dfs(idx + 2, calc(sum, op[idx + 1], op[idx + 2] - '0')); 49 | } 50 | if (idx + 4 <= N) 51 | { 52 | dfs(idx + 4, calc(sum, op[idx + 1], calc(op[idx + 2] - '0', op[idx + 3], op[idx + 4] - '0'))); 53 | } 54 | } 55 | 56 | int main() 57 | { 58 | ios_base::sync_with_stdio(false); 59 | cout.tie(0); 60 | cin.tie(0); 61 | 62 | init(); 63 | 64 | if (N == 1) { 65 | cout << op[1] - '0' << endl; 66 | } 67 | else { 68 | dfs(1, op[1] - '0'); 69 | cout << answer << endl; 70 | } 71 | return 0; 72 | } -------------------------------------------------------------------------------- /source/kim-dabin/Prog_2XNTiling.md: -------------------------------------------------------------------------------- 1 | # [프로그래머스 / 자바] 2XN 타일링 2 | 3 | https://programmers.co.kr/learn/courses/30/lessons/12900# 4 | 5 | 6 | 7 | ## 접근 방식 8 | 9 | - dp[i]=dp[i-1]+dp[i-2] 10 | 11 | 12 | 13 | ## 소스 구현 14 | 15 | ```java 16 | class Solution { 17 | public int solution(int n) { 18 | int answer = 0; 19 | int[] dp = new int[n+1]; 20 | dp[0]=1; 21 | dp[1] = 1; 22 | for(int i=2; i<=n; i++){ 23 | dp[i]= (dp[i-1]+dp[i-2])%1000000007; 24 | 25 | } 26 | 27 | return dp[n]; 28 | } 29 | } 30 | ``` 31 | 32 | 33 | 34 | ## 테스트 35 | 36 | ### 정확성 테스트 37 | 38 | ```tex 39 | 테스트 1 〉 통과 (0.96ms, 53MB) 40 | 테스트 2 〉 통과 (0.90ms, 50.2MB) 41 | 테스트 3 〉 통과 (0.92ms, 50.2MB) 42 | 테스트 4 〉 통과 (1.13ms, 50.3MB) 43 | 테스트 5 〉 통과 (0.85ms, 52.3MB) 44 | 테스트 6 〉 통과 (1.08ms, 53MB) 45 | 테스트 7 〉 통과 (0.90ms, 50.6MB) 46 | 테스트 8 〉 통과 (3.26ms, 50.1MB) 47 | 테스트 9 〉 통과 (1.01ms, 52.5MB) 48 | 테스트 10 〉 통과 (1.16ms, 50.6MB) 49 | 테스트 11 〉 통과 (0.92ms, 50.2MB) 50 | 테스트 12 〉 통과 (0.89ms, 52.2MB) 51 | 테스트 13 〉 통과 (1.01ms, 52.7MB) 52 | 테스트 14 〉 통과 (1.00ms, 51MB) 53 | ``` 54 | 55 | ### 효율성 테스트 56 | 57 | ```tex 58 | 테스트 1 〉 통과 (1.37ms, 49.9MB) 59 | 테스트 2 〉 통과 (1.67ms, 51.9MB) 60 | 테스트 3 〉 통과 (1.30ms, 50MB) 61 | 테스트 4 〉 통과 (1.34ms, 52.1MB) 62 | 테스트 5 〉 통과 (2.04ms, 52MB) 63 | 테스트 6 〉 통과 (2.77ms, 53MB) 64 | ``` 65 | 66 | -------------------------------------------------------------------------------- /source/lee/200227_hash.md: -------------------------------------------------------------------------------- 1 | # 위장 2 | - https://programmers.co.kr/learn/courses/30/lessons/42578 3 | 4 | ## 문제 접근 방법 5 | 1. clothes의 각 행은 [의상의 이름, 의상의 종류]으로 이루어져 있다. Map을 이용해 K에 의상의 종류, V에 의상을 담기로 함. 6 | 2. Map로 V에 의상 이름을 담는 것이 아니라 의상 갯수만 담음. 리스트나 배열로 의상 이름을 담아도 상관 없지만, 결국 경우의 수를 구해야 하기 때문에 계산 편의성을 위해 Integer로 설정 7 | 3. 각 의상 종류별(K) 의상 갯수(V)에 1을 더한 값(안 입는 경우)을 전부 곱한 후, 마지막에 1을 뺌(전부 안 입는 경우의 수) 8 | 9 | ### 문제점 10 | 1, 2까지는 금방 했는데 3에서 모든 경우의 수를 하나하나 구하는 공식을 생각하고 있었다. 우연히 3을 떠올리고 전체 경우의 수 직접 구한것과 비교해보니 똑같아서 풀이방법을 확신하게 됨 11 | 12 | ## 코드 구현 13 | ```java 14 | import java.util.*; 15 | 16 | public class Solution { 17 | public int solution(String[][] clothes) { 18 | Map map = new HashMap<>(); 19 | 20 | for (int i = 0; i < clothes.length; i++) { 21 | String key = clothes[i][1]; 22 | int values = map.containsKey(key) ? map.get(key) + 1 : 1; 23 | map.put(key, values); 24 | } 25 | 26 | int count = 1; 27 | for (Map.Entry entry : map.entrySet()) { 28 | count *= (entry.getValue() + 1); 29 | } 30 | int answer = count - 1; 31 | return answer; 32 | } 33 | } 34 | ``` 35 | 36 | ### Time complexity 37 | O(n+m) n: clothes.length의 길이(전체 의상 수), m: map의 크기 38 | 39 | ### Space complexity 40 | O(m) m:map의 크기(의상 종류 수) 41 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj12852.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | typedef pair Pair; 13 | 14 | int main() 15 | { 16 | ios_base::sync_with_stdio(0); 17 | cout.tie(0); 18 | cin.tie(0); 19 | 20 | int N; 21 | cin >> N; 22 | 23 | queueq; 24 | vectorstep(N + 1); 25 | 26 | q.push(1); 27 | 28 | while (q.empty() != true) 29 | { 30 | int pos = q.front(); 31 | q.pop(); 32 | 33 | if (pos == N) 34 | break; 35 | 36 | if (pos * 3 <= N && step[pos * 3].second == 0) { 37 | q.push(pos * 3); 38 | step[pos * 3].second = step[pos].second + 1; 39 | step[pos * 3].first = pos; 40 | } 41 | 42 | if (pos * 2 <= N && step[pos * 2].second == 0) { 43 | q.push(pos * 2); 44 | step[pos * 2].second = step[pos].second + 1; 45 | step[pos * 2].first = pos; 46 | } 47 | 48 | if (pos + 1 <= N && step[pos + 1].second == 0) { 49 | q.push(pos + 1); 50 | step[pos + 1].second = step[pos].second + 1; 51 | step[pos + 1].first = pos; 52 | } 53 | } 54 | 55 | cout << step[N].second << endl; 56 | 57 | while (true) 58 | { 59 | if (N == 0)break; 60 | cout << N << " "; 61 | N = step[N].first; 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj13913.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int N, K; 11 | 12 | void init() 13 | { 14 | cin >> N >> K; 15 | } 16 | 17 | void bfs() 18 | { 19 | queueq; 20 | vectordist(100001, -1); 21 | vectorstep(100001); 22 | 23 | dist[N] = 0; 24 | q.push(N); 25 | 26 | while (q.empty() != true) 27 | { 28 | int pos = q.front(); 29 | q.pop(); 30 | 31 | if (pos == K) 32 | { 33 | cout << dist[pos] << endl; 34 | 35 | stackst; 36 | 37 | while (pos != N) { 38 | st.push(pos); 39 | pos = step[pos]; 40 | } 41 | 42 | st.push(N); 43 | 44 | while (st.empty() != true) { 45 | cout << st.top() << " "; 46 | st.pop(); 47 | } 48 | break; 49 | } 50 | 51 | for (int i = 1; i <= 3; i++) 52 | { 53 | int next = pos; 54 | 55 | if (i == 1) next--; 56 | else if (i == 2) next++; 57 | else next *= 2; 58 | 59 | if (next < 0 || next>100000 || dist[next] >= 0) 60 | continue; 61 | 62 | dist[next] = dist[pos] + 1; 63 | step[next] = pos; 64 | q.push(next); 65 | } 66 | } 67 | } 68 | 69 | int main() 70 | { 71 | ios_base::sync_with_stdio(0); 72 | cout.tie(0); 73 | cin.tie(0); 74 | 75 | init(); 76 | bfs(); 77 | return 0; 78 | } -------------------------------------------------------------------------------- /source/ohhako/200208_array&string.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 연습문제 2 | - 시저 암호 3 | - https://programmers.co.kr/learn/courses/30/lessons/12926 4 | 5 | ### 비슷한 문제 6 | - [수박수?](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200206_string2.md#%EC%88%98%EB%B0%95%EC%88%98) 7 | - [모의고사](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200128_%EC%99%84%EC%A0%84%ED%83%90%EC%83%89.md#%EB%AA%A8%EC%9D%98%EA%B3%A0%EC%82%AC) 8 | 9 | ### 접근 방법을 적용한 코드 10 | ```java 11 | import java.util.*; 12 | class Solution { 13 | public String solution(String s, int n) { 14 | String answer = ""; 15 | String alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 16 | String alphabet_lower = "abcdefghijklmnopqrstuvwxyz"; 17 | String[] apb_up = alphabet_upper.split(""); 18 | String[] apb_low = alphabet_lower.split(""); 19 | String[] str = s.split(""); 20 | StringBuffer sb = new StringBuffer(); 21 | 22 | for(int i=0 ; i 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef pair>Pair; 8 | 9 | int N; 10 | vectorv; 11 | 12 | void init() 13 | { 14 | cin >> N; 15 | 16 | for (int i = 0; i < N; i++) { 17 | int val; 18 | cin >> val; 19 | v.push_back(val); 20 | } 21 | } 22 | 23 | void solve() 24 | { 25 | vectordp(N); 26 | 27 | for (int i = 0; i < v.size(); i++) 28 | { 29 | int MAX = 0; 30 | int idx = -1; 31 | 32 | for (int j = 0; j < i; j++) 33 | { 34 | if (v[i] > v[j]) 35 | { 36 | if (MAX < dp[j].first) 37 | { 38 | MAX = dp[j].first; 39 | idx = j; 40 | } 41 | } 42 | } 43 | dp[i].first = (MAX + 1); 44 | if (idx != -1)dp[i].second = dp[idx].second; 45 | dp[i].second.push_back(v[i]); 46 | } 47 | 48 | Pair answer = { 0,{} }; 49 | 50 | for (int i = 0; i < dp.size(); i++) 51 | { 52 | if (answer.first < dp[i].first) 53 | { 54 | answer.first = dp[i].first; 55 | answer.second = dp[i].second; 56 | } 57 | } 58 | 59 | cout << answer.first << endl; 60 | 61 | for (auto elem : answer.second) 62 | cout << elem << " "; 63 | cout << endl; 64 | } 65 | 66 | int main() 67 | { 68 | ios_base::sync_with_stdio(0); 69 | cout.tie(0); 70 | cin.tie(0); 71 | 72 | init(); 73 | solve(); 74 | return 0; 75 | } -------------------------------------------------------------------------------- /source/lee/200314_dfs.md: -------------------------------------------------------------------------------- 1 | # 타겟 넘버 2 | - https://programmers.co.kr/learn/courses/30/lessons/43165 3 | 4 | ## 문제 접근 방법 5 | 처음엔 예시문제에 나온 것 처럼 정확하게 5가지만 구하는 방법인줄 알았다. 힌트 보니 모든 경우의 수를 따지는 거였다. 6 | 1. 이진트리 구성으로 한 노트는 +의 값을, 다른 한 노드는 -의 값을 갖게 한다. 7 | 2. leaf node에 다다를 경우 지금까지의 sum이 target과 맞는지 비교, 맞다면 정답 카운트 증가 8 | 예시: numbers={1. 1}, target=2 9 | ``` 10 | 0 11 | / \ 12 | -1 1 13 | / \ / \ 14 | -1 1 -1 1 15 | ---------------------------- 16 | sum: -2 0 0 2 17 | answer카운트 증가 18 | ``` 19 | 20 | ## 코드 구현 21 | ```java 22 | class Solution { 23 | int answer = 0; 24 | 25 | public int solution(int[] numbers, int target) { 26 | int index = 0; 27 | int sum = 0; 28 | calculate(numbers, index, sum, target); 29 | return answer; 30 | } 31 | 32 | private void calculate(int[] numbers, int index, int sum, int target) { 33 | if (index == numbers.length) { 34 | if (sum == target) answer++; 35 | return; 36 | } 37 | calculate(numbers, index + 1, sum + numbers[index], target); 38 | calculate(numbers, index + 1, sum - numbers[index], target); 39 | } 40 | } 41 | ``` 42 | 43 | ### Time complexity 44 | O(2^n) n:numbers.length 45 | numbers의 모든 원소를 +나 -로 계산하는 경우의 수 46 | 47 | ### Space complexity 48 | O(1) 49 | -------------------------------------------------------------------------------- /source/lee/200309_dp.md: -------------------------------------------------------------------------------- 1 | # 정수 삼각형 2 | https://programmers.co.kr/learn/courses/30/lessons/43105 3 | 4 | ## 문제 접근 방법 5 | - 각 줄마다 경로 합의 최댓값을 구해 dp배열에 저장 6 | - dp배열 각 줄의 맨 처음과 끝 원소는 바로 윗줄의 값에서 구할 수 있음 7 | - dp배열 제일 마지막 줄에는 각 원소로 도착하는 최대 경로값이 구해져 있다. 그 줄에서 최댓값을 구하면 답 8 | - 다른 사람의 풀이를 보니 입력값 triangle을 그대로 사용함. 나도 처음엔 triangle배열을 그대로 이용할까 싶었지만(코드의 가독성을 위해) 실제 일이라면 나중에 triangle이 다른 곳에서 쓰일지도 모르니 웬만하면 복사해서 쓰는 일이 더 많을거라고 판단함. 대신 다른 풀이는 마지막에 최댓값을 stream 사용해서 구했던데 그건 좋아보인다. 9 | 10 | ### 해결한 코드 11 | ```java 12 | import java.lang.Math; 13 | class Solution { 14 | public int solution(int[][] triangle) { 15 | int[][] dp = triangle; 16 | 17 | for (int i = 1; i < triangle.length; i++) { 18 | int levelLength = triangle[i].length; 19 | dp[i][0] = dp[i-1][0]+triangle[i][0]; 20 | dp[i][levelLength-1]=dp[i-1][levelLength-2]+triangle[i][levelLength-1]; 21 | for (int j = 1; j < levelLength-1; j++) { 22 | dp[i][j]=Math.max(dp[i-1][j],dp[i-1][j-1])+triangle[i][j]; 23 | } 24 | } 25 | int answer = 0; 26 | for (int k = 0; k < dp[dp.length - 1].length; k++) 27 | answer = Math.max(answer, dp[dp.length - 1][k]); 28 | 29 | return answer; 30 | } 31 | } 32 | ``` 33 | ### Time complexity 34 | O(N^2) N=triangle 원소 개수 35 | triangle의 모든 원소를 방문 36 | 37 | ### Space complexity 38 | O(N) 39 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/BOJ-16948 데스나이트.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | typedef pair Pair; 12 | 13 | const int idx_1[] = { -2,-2,0,0,2,2 }; 14 | const int idx_2[] = { -1,1,-2,2,-1,1 }; 15 | 16 | int N; 17 | Pair start, goal; 18 | int step[201][201]; 19 | 20 | void init() 21 | { 22 | cin >> N; 23 | cin >> start.first >> start.second >> goal.first >> goal.second; 24 | } 25 | 26 | void bfs() 27 | { 28 | queueq; 29 | q.push(start); 30 | 31 | while (q.empty() != true) 32 | { 33 | Pair pos = q.front(); 34 | q.pop(); 35 | 36 | if (pos == goal) { 37 | cout << step[pos.first][pos.second] << endl; 38 | return; 39 | } 40 | 41 | for (int i = 0; i < 6; i++) 42 | { 43 | Pair next = Pair(pos.first + idx_1[i], pos.second + idx_2[i]); 44 | 45 | if (next.first < 0 || next.first >= N || next.second < 0 || next.second >= N) 46 | continue; 47 | 48 | if (!step[next.first][next.second]) 49 | { 50 | step[next.first][next.second] = step[pos.first][pos.second] + 1; 51 | q.push(next); 52 | } 53 | } 54 | } 55 | cout << -1 << endl; 56 | } 57 | 58 | int main() 59 | { 60 | ios_base::sync_with_stdio(0); 61 | cout.tie(0); 62 | cin.tie(0); 63 | 64 | init(); 65 | bfs(); 66 | return 0; 67 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1074(재귀).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | int N, R, C; 14 | int answer = -1; 15 | 16 | void init() 17 | { 18 | cin >> N >> R >> C; 19 | } 20 | 21 | bool solve(int idx1, int idx2, int depth) 22 | { 23 | if (depth == 1) 24 | { 25 | answer++; 26 | 27 | if (idx1 == R && idx2 == C) { 28 | return true; 29 | } 30 | 31 | answer++; 32 | 33 | if (idx1 == R && idx2 + 1 == C) { 34 | return true; 35 | } 36 | 37 | answer++; 38 | 39 | if (idx1 + 1 == R && idx2 == C) { 40 | return true; 41 | } 42 | 43 | answer++; 44 | 45 | if (idx1 + 1 == R && idx2 + 1 == C) { 46 | return true; 47 | } 48 | 49 | return false; 50 | } 51 | 52 | if (solve(idx1, idx2, depth / 2)) 53 | return true; 54 | 55 | if (solve(idx1, idx2 + depth, depth / 2)) 56 | return true; 57 | 58 | if (solve(idx1 + depth, idx2, depth / 2)) 59 | return true; 60 | 61 | if (solve(idx1 + depth, idx2 + depth, depth / 2)) 62 | return true; 63 | 64 | return false; 65 | } 66 | 67 | int main() 68 | { 69 | ios_base::sync_with_stdio(0); 70 | cout.tie(0); 71 | cin.tie(0); 72 | 73 | init(); 74 | solve(0, 0, pow(2, N) / 2); 75 | cout << answer << endl; 76 | return 0; 77 | } -------------------------------------------------------------------------------- /source/woodi/200821_Ladder.md: -------------------------------------------------------------------------------- 1 | # 백준 문제 2 | - 사다리 3 | - https://www.acmicpc.net/problem/2022 4 | 5 | ### 풀이 방법 6 | 7 | #### 문제 접근 방법 8 | - c = h1*h2 / (h1+h2)라는 방정식에 임의의 d값을 대입하여 주어진 c값과 얼마나 유사한지 검사한다 9 | 10 | ### 구현 배경 지식 11 | - 이분 탐색 12 | #### 접근 방법을 적용한 코드 13 | 14 | ```java 15 | 16 | import java.util.*; 17 | class Solution { 18 | 19 | static double getC(double x, double y, double d) { 20 | double h1 = Math.sqrt(x*x-d*d); 21 | double h2 = Math.sqrt(y*y-d*d); 22 | 23 | return h1*h2/(h1+h2); 24 | 25 | } 26 | public static void main(String[] args) { 27 | Scanner sc = new Scanner(System.in); 28 | double x = sc.nextDouble(); 29 | double y = sc.nextDouble(); 30 | double c = sc.nextDouble(); 31 | double d; // 우리가 구해야할 값 32 | 33 | // 입력값 중 더 큰 값을 x에 저장하겠다. 34 | if(y>x) { 35 | double temp = x; 36 | x=y; 37 | y=temp; 38 | } 39 | 40 | double l=0; // d의 최소값 41 | double r=y; // d의 최대값 42 | double newC; 43 | 44 | // 이분탐색을 통해 주어진 C와 가장 근사한 newC륾 만드는 d를 찾는다. 45 | while(true) { 46 | d = (l+r)/2; // d의 값을 l과 r의 중간 값으로 잡는다. 47 | newC = getC(x,y,d); 48 | 49 | // c-newC가 0.001미만이면 종료한다. 50 | if(Math.abs(c-newC)<0.001) { 51 | System.out.println(d); 52 | break; 53 | } 54 | 55 | // 폭이 실제보다 좁다. --> d 증가 시켜야 56 | if(newC >c) { 57 | l=d; 58 | }else { 59 | r=d; 60 | } 61 | 62 | } 63 | 64 | } 65 | } 66 | ``` 67 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1939(kruskal).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef pair, int> Pair; 8 | 9 | int N, M; 10 | int parent[10001]; 11 | vectoredges; 12 | int start, goal; 13 | 14 | bool comp(Pair p1, Pair p2) 15 | { 16 | return p1.second > p2.second ? true : false; 17 | } 18 | 19 | int getParent(int idx) { 20 | if (idx == parent[idx]) 21 | return idx; 22 | else 23 | return getParent(parent[idx]); 24 | } 25 | 26 | void merge(int idx1, int idx2) 27 | { 28 | int p1 = getParent(idx1); 29 | int p2 = getParent(idx2); 30 | 31 | if (p1 != p2) 32 | parent[p1] = p2; 33 | } 34 | 35 | void init() 36 | { 37 | cin >> N >> M; 38 | 39 | for (int i = 0; i < M; i++) 40 | { 41 | int A, B, C; 42 | cin >> A >> B >> C; 43 | edges.push_back(Pair(make_pair(A, B), C)); 44 | } 45 | 46 | cin >> start >> goal; 47 | 48 | for (int i = 0; i <= N; i++) 49 | parent[i] = i; 50 | 51 | sort(edges.begin(), edges.end(), comp); 52 | } 53 | 54 | void solve() 55 | { 56 | for (auto elem : edges) 57 | { 58 | merge(elem.first.first, elem.first.second); 59 | 60 | if (getParent(start) == getParent(goal)) 61 | { 62 | cout << elem.second << endl; 63 | return; 64 | } 65 | } 66 | } 67 | 68 | int main() 69 | { 70 | ios_base::sync_with_stdio(0); 71 | cout.tie(0); 72 | cin.tie(0); 73 | 74 | init(); 75 | solve(); 76 | return 0; 77 | } -------------------------------------------------------------------------------- /source/soyeon/[boj] 2110.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 스택/큐 문제 2 | - 공유기 설치 3 | - https://www.acmicpc.net/problem/2110 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | C개의 공유기를 N개의 집에 적당히 설치해서, 가장 인접한 두 공유기 사이의 거리를 최대를 구하는 문제이다. 8 | 9 | ### 문제 접근 방법 10 | 공유기를 어떤 거리 D로 설치할 때 모든 집이 와이파이를 사용할수 있는지/없는지 판단하는 문제로 바꾼다. 11 | 거리 D를 구할 때에는 이분 탐색으로 구하도록 한다. 12 | 13 | ### 구현 배경 지식 14 | 이분 탐색 15 | 16 | ### 접근 방법을 적용한 코드 17 | ```java 18 | import java.util.*; 19 | import java.io.*; 20 | 21 | public class Main { 22 | public static void main(String[] args) { 23 | Scanner in = new Scanner(System.in); 24 | int n = in.nextInt(); 25 | int c = in.nextInt(); 26 | int home[] = new int[n]; 27 | for (int i = 0; i < n; i++) { 28 | home[i] = in.nextInt(); 29 | } 30 | Arrays.sort(home); 31 | 32 | int low = 1; 33 | int high = home[n - 1] - home[0]; 34 | int mid = 0; 35 | while (low < high) { 36 | mid = (low + high) / 2; 37 | 38 | if (isPossible(mid, home, c)) { 39 | low = mid + 1; 40 | } else { 41 | high = mid; 42 | } 43 | } 44 | System.out.println(low); 45 | } 46 | 47 | public static boolean isPossible(int distance, int home[], int c) { 48 | int num = 1; 49 | int currentPos = home[0]; 50 | for (int i = 1; i < home.length; i++) { 51 | if (home[i] - currentPos > distance) { 52 | num += 1; 53 | currentPos = home[i]; 54 | } 55 | } 56 | 57 | if (num < c) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | ``` 64 | -------------------------------------------------------------------------------- /source/woodi/201023_Programmers_43238.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 이분탐색문제 2 | - 입국심사 3 | - https://programmers.co.kr/learn/courses/30/lessons/43238 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 입국심사를 기다리는 사람 수 n 8 | - int[] times : 각 심사관이 한 명을 심사하는데 걸리는 시간이 담긴 배열 9 | - 가장 앞에 서 있는 사람은 비어 있는 심사대로 가서 심사를 받을 수 있습니다. 하지만 더 빨리 끝나는 심사대가 있으면 기다렸다가 그곳으로 가서 심사를 받을 수도 있습니다. 10 | - 모든 사람이 심사를 받는데 걸리는 최소 시간을 구하시오. 11 | 12 | 13 | ### 문제 접근 방법 14 | - 정답을 가정(mid)하고 조건(n)과 비교한다. -> 가장 n과 유사한 mid가 정답 15 | - mid 시간 이내에 심사 가능한 인원의 수 -> sum(mid/times[i])=result, n과 result 비교, n== result이면 mid 값을 반환한다. 16 | ### 구현 배경 지식 17 | - 이분탐색 18 | ### 접근 방법을 적용한 코드 19 | ```java 20 | import java.util.*; 21 | 22 | class Solution { 23 | public long solution(int n, int[] times) { 24 | long answer = 0; 25 | Arrays.sort(times); 26 | long left =1; 27 | long right = (long)n*times[times.length-1]; // 가장 오래 걸리는 경우 28 | while(left<=right){ 29 | long mid = (left+right)/2; 30 | long sum=0; // mid 시간 이내에 심사 가능한 인원의 수 31 | for(int t : times){ 32 | sum+= (mid/t); 33 | } 34 | if(sum hashmap = new HashMap(); 22 | 23 | StringTokenizer st = new StringTokenizer(s, "{},", false); 24 | Integer input = 0; 25 | while (st.hasMoreTokens()) { 26 | input = Integer.valueOf(st.nextToken()); 27 | 28 | hashmap.put(input, hashmap.getOrDefault(input, 0) + 1); 29 | } 30 | 31 | // hashmap 의 value 기준 정렬 32 | List keySetList = new ArrayList<>(hashmap.keySet()); 33 | Collections.sort(keySetList, new Comparator() { 34 | 35 | @Override 36 | public int compare(Integer o1, Integer o2) { 37 | return hashmap.get(o2).compareTo(hashmap.get(o1)); 38 | } 39 | 40 | }); 41 | 42 | int index = 0; 43 | int answer[] = new int[keySetList.size()]; 44 | for (Integer key : keySetList) { 45 | answer[index++] = key; 46 | } 47 | return answer; 48 | } 49 | } 50 | ``` 51 | -------------------------------------------------------------------------------- /source/kim-dabin/BJ_1495.md: -------------------------------------------------------------------------------- 1 | # [백준/자바] 1495번 기타리스트 2 | 3 | 4 | 5 | ## 소스 구현 6 | 7 | ```java 8 | import java.io.BufferedReader; 9 | import java.io.InputStreamReader; 10 | 11 | public class BJ1495_ver4 { 12 | static int N, S, M, max; 13 | static int[] v; 14 | 15 | public static void dp() { 16 | boolean[][] dp = new boolean[N + 1][M + 1]; 17 | dp[0][S] = true; 18 | for (int i = 1; i <= N; i++) { 19 | for (int j = 0; j <= M; j++) { 20 | 21 | if (!dp[i - 1][j]) { // volume이 있을 때만 22 | continue; 23 | } 24 | 25 | if (j - v[i - 1] >= 0 && j - v[i - 1] <= M) { 26 | dp[i][j - v[i - 1]] = true; 27 | } 28 | if (j + v[i - 1] >= 0 && j + v[i - 1] <= M) { 29 | dp[i][j + v[i - 1]] = true; 30 | } 31 | } 32 | } 33 | 34 | for (int i = M; i >= 0; i--) { 35 | if (dp[N][i]) { 36 | max = i; 37 | break; 38 | } 39 | 40 | } 41 | 42 | }// dp() end 43 | 44 | public static void main(String[] args) throws Exception { 45 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 46 | String[] str = br.readLine().split(" "); 47 | N = Integer.valueOf(str[0]); 48 | S = Integer.valueOf(str[1]); 49 | M = Integer.valueOf(str[2]); 50 | v = new int[N]; 51 | max = -1; 52 | String[] vStr = br.readLine().split(" "); 53 | for (int i = 0; i < N; i++) { 54 | v[i] = Integer.valueOf(vStr[i]); 55 | } 56 | dp(); 57 | System.out.println(max); 58 | 59 | } 60 | } 61 | 62 | ``` 63 | 64 | -------------------------------------------------------------------------------- /source/ohhako/coding test/kakao/2019_오픈채팅방.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | class Solution { 3 | public String[] solution(String[] record) { 4 | HashMap users = new HashMap<>(); 5 | int sizeOfManagerMessage = 0; 6 | for(int i=0 ; i 32 | #### Math.pow(밑 base, 지수 expo) 33 | 밑 값을 지수만큼 제곱시킨 값을 반환한다. 34 | 35 | 36 | 37 | ## 수학이론으로 접근한 문제 38 | - n진법 39 | - [124나라의 숫자](https://programmers.co.kr/learn/courses/30/lessons/12899#) 40 | - [비밀지도](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/coding%20test/kakao/2017_%EB%B9%84%EB%B0%80%EC%A7%80%EB%8F%84.md) 41 | - 공약수, 공배수 42 | - [멀쩡한사각형](https://programmers.co.kr/learn/courses/30/lessons/62048) 43 | - [최대공약수와 최소공배수](https://programmers.co.kr/learn/courses/30/lessons/12940) 44 | - 소수 45 | - [소수찾기](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200207_string4.md) 46 | - [소수 구하기](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200227_BF.md) 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /source/lee/team/200409_기타리스트.md: -------------------------------------------------------------------------------- 1 | # 기타리스트 2 | 3 | https://www.acmicpc.net/problem/1495 4 | 5 | ## 문제 접근 방법 6 | 7 | dfs로 접근 8 | 9 | 1. 각 볼륨 값을 더하거나 뺀 값의 최댓값을 재귀적으로 구함 10 | 2. 0보다 작거나 M보다 큰 값이면 -1 리턴 11 | 예: 12 | 13 | ``` 14 | 3 5 10 15 | 5 3 7 16 | 17 | 5 18 | +5 / \ -5 19 | 10 0 20 | +3/ \-3 +3/ \-3 21 | -1 7 3 -1 22 | +7/ \-7 +7/ \-7 23 | -1 0 10 -1 24 | ``` 25 | 26 | ### 시간초과 코드 27 | 28 | ```java 29 | import java.io.IOException; 30 | import java.util.Scanner; 31 | 32 | public class Baekjoon1495 { 33 | static int M; 34 | static int S; 35 | static int N; 36 | static int[] V; 37 | 38 | public static void main(String[] args) throws IOException { 39 | Scanner s = new Scanner(System.in); 40 | N = s.nextInt(); 41 | S = s.nextInt(); 42 | M = s.nextInt(); 43 | 44 | V = new int[N]; 45 | for (int i = 0; i < N; i++) { 46 | V[i] = s.nextInt(); 47 | } 48 | 49 | System.out.println(solution(0, S)); 50 | } 51 | 52 | public static int solution(int idx, int p) { 53 | if (p < 0 || p > M) return -1; 54 | if (idx == N) return p; 55 | return Math.max(solution(idx + 1, p + V[idx]), solution(idx + 1, p - V[idx])); 56 | } 57 | } 58 | ``` 59 | 60 | ### Time complexity 61 | 62 | O(2^N) 63 | 64 | ### Space complexity 65 | 66 | O(N) 67 | -------------------------------------------------------------------------------- /source/soyeon/[leetcode]55.md: -------------------------------------------------------------------------------- 1 | # Leetcode 문제 2 | - Jump Game 3 | - https://leetcode.com/problems/jump-game/ 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 배열에 쓰여있는 수 이하로 점프를 할 때 배열의 마지막 위치에 도착할 수 있는지 구하는 문제이다. 8 | 9 | ### 문제 접근 방법 10 | - reach 배열을 따로 만들어서 reach[i]를 i번째 칸에 도달할 수 있으면 1, 없으면 0으로 저장한다. 11 | - 배열을 순서대로 가면서 i번째 칸에 도착할 수 있다면 그 칸에서 갈 수 있는 모든 곳을 표시한다. 12 | 13 | - list에 원소가 하나만 있을 때를 생각하지 않아서 많이 틀렸다. 14 | 15 | ### 접근 방법을 적용한 코드 16 | - 시간복잡도 O(N^2) 17 | ```java 18 | class Solution { 19 | public boolean canJump(int[] list) { 20 | int length=list.length; 21 | int reach[]=new int[length]; 22 | 23 | reach[0]=1; 24 | for(int idx=0;idx reachable) return false; 51 | reachable = Math.max(reachable, i + list[i]); 52 | } 53 | return true; 54 | } 55 | } 56 | ``` 57 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj14267.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | typedef pair Pair; 14 | 15 | int N, M; 16 | vectorGP[100001]; 17 | vectorinput; 18 | int visited[100001]; 19 | int step[100001]; 20 | 21 | void init() 22 | { 23 | cin >> N >> M; 24 | 25 | for (int i = 1; i <= N; i++) { 26 | int n; 27 | cin >> n; 28 | if (i == -1) continue; 29 | GP[n].push_back(i); 30 | } 31 | 32 | for (int i = 0; i < M; i++) { 33 | int k, w; 34 | cin >> k >> w; 35 | input.push_back(Pair(k, w)); 36 | } 37 | } 38 | 39 | void bfs(int n) 40 | { 41 | queueq; 42 | q.push(n); 43 | visited[n] = 1; 44 | 45 | while (q.empty() != true) 46 | { 47 | int pos = q.front(); 48 | q.pop(); 49 | 50 | for (auto elem : GP[pos]) 51 | { 52 | if (!visited[elem]) 53 | { 54 | step[elem] += step[pos]; 55 | visited[elem] = 1; 56 | q.push(elem); 57 | } 58 | } 59 | } 60 | } 61 | 62 | void solve() 63 | { 64 | for (auto elem : input) { 65 | step[elem.first] += elem.second; 66 | } 67 | 68 | bfs(1); 69 | 70 | for (int i = 1; i <= N; i++) { 71 | cout << step[i] << " "; 72 | } 73 | cout << endl; 74 | } 75 | 76 | int main() 77 | { 78 | ios_base::sync_with_stdio(0); 79 | cout.tie(0); 80 | cin.tie(0); 81 | 82 | init(); 83 | solve(); 84 | return 0; 85 | } -------------------------------------------------------------------------------- /source/ohhako/200429_dp.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 연습 문제 2 | 3 | - 2xn 타일링 4 | - https://programmers.co.kr/learn/courses/30/lessons/12900 5 | 6 | ## 풀이 방법 7 | 8 | ### 문제 이해하기 9 | 10 | - 가로2 세로1 길이의 타일로 가로n 세로2의 바닥을 가득 채워야 한다. 11 | - 타일 하나는 가로 배치, 세로 배치 두 가지를 할 수 있다. 12 | 13 | ### 문제 접근 방법 14 | 15 | - 가로 길이가 1씩 늘어날때 마다 추가되는 타일의 모양을 직접 그려 확인한다. 16 | - dp[i ]: 가로 길이가 i일때 배치 가능한 바닥의 개수 17 | - i 바닥 개수는 i-1 바닥의 오른쪽에 1x2 타일을 붙인 개수 d[n-1 ]를 포함한다. 18 | - 그 외에 새로 추가되는 바닥이 있다. 바닥의 맨 오른쪽 끝 가로2의 부분을 가로2 세로1 타일 두개로 채울 수 있는 것이다. 19 | - 위 패턴의 개수는 i-2까지 바닥 개수에 하나의 패턴을 추가하므로 d[n-2 ]를 포함한다. 20 | - `제한사항`을 제대로 확인해야 한다. 반복문을 수행하며 값이 커질 수 있으니 1,000,000,007으로 나눈 나머지 값을 저장해야 했다. 21 | 22 | ### 구현 배경 지식 23 | 24 | ### 접근 방법을 적용한 코드 25 | 26 | ```java 27 | class Solution { 28 | public int solution(int n) { 29 | int[] dp = new int[n+1]; 30 | dp[0] = 1; 31 | dp[1] = 1; 32 | for(int i=2 ; i<=n ; i++){ 33 | dp[i] = (dp[i-1]+dp[i-2])%1000000007; 34 | } 35 | return dp[n]%1000000007; 36 | } 37 | } 38 | ``` 39 | 40 | ### 못풀었던 이유 41 | 42 | - 가로2,세로1 두개가 추가되는 타일이 이전에 저장한 바닥 갯수가 아닌 상수 k개 대로 늘어나는 줄 알았다. 하지만 i=6 부터는 그림을 직접 그리는게 부담스러워 졌다. 문제에서 주어진 그림은 n=4 이다. `n=4 까지 그리면서 패턴을 파악하라. 그 이상은 갈 필요가 없다` 는 의도같았다. 43 | - i가 1씩 늘어나며 진행될때 이전 바닥에서 안보이는 패턴이 등장하길래 홀수/짝수 를 나누어서 규칙을 찾아야 하는줄 알았다. 처음에 나왔던 식은 아래와 같았다. 그리고 테스트 케이스에서 통과하지 못해서 n=5를 그려봤는데 새로운 패턴이 3개나 늘어난걸 확인했다. 44 | 45 | ```java 46 | if(i%2==0) 47 | dp[i] = dp[i-1] + dp[i-2]; 48 | else 49 | dp[i] = dp[i-1] + 1; 50 | ``` 51 | -------------------------------------------------------------------------------- /source/ohhako/boj/bj_1945.md: -------------------------------------------------------------------------------- 1 | # 백준 DP 문제 2 | 3 | - 기타리스트 4 | - https://www.acmicpc.net/problem/1495 5 | 6 | ## 풀이 방법 7 | 8 | ### 문제 이해하기 9 | 10 | - Input: 곡의 개수(N), 시작 볼륨(S), M, 볼륨목록(v[]) 11 | - 현재 볼륨이 p일때 i번째 곡은 p + v[ i ] 혹은 p - v[ i ] 이다. 12 | - Output: 마지막곡이 연주가능한 볼륨 중 최대값이 되도록 한다. 13 | 14 | ### 해결하지 못한 이유 15 | 16 | - 다시 돌아와야 하는 순서도 or 모든 연산에 대한 값을 저장하는 방법을 찾지 못했다. 17 | 18 | ### 접근 방법을 적용한 코드 19 | 20 | ```java 21 | import java.io.BufferedReader; 22 | import java.io.InputStreamReader; 23 | import java.io.IOException; 24 | 25 | public class Main{ 26 | 27 | public static void solution(int n,int s,int m,int[][] vol){ 28 | //[i][0]는 누적 볼륨 29 | 30 | System.out.println(answer); 31 | } 32 | public static void main(String[] args){ 33 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 34 | String[] cmd = br.readLine(); 35 | int n = Integer.parseInt(cmd[0]); 36 | int s = Integer.parseInt(cmd[1]); 37 | int m = Integer.parseInt(cmd[2]); 38 | String[] vol_str = br.readLine().split(" "); 39 | int[][] vol = new int[n][2]; 40 | for(int i=0 ; i 58 | 59 | --- 60 | 61 | 아래의 사이트를 참고해 작성된 글입니다. 62 | -------------------------------------------------------------------------------- /source/lee/team/20200427_타일채우기.md: -------------------------------------------------------------------------------- 1 | # 타일 채우기 2 | 3 | https://www.acmicpc.net/problem/2133 4 | 5 | ## 문제 접근 방법 6 | 7 | 1. F(N-2)인 상태에서 F(N)이 되기 위해선 제일 마지막 두 칸에 `F(2)=3`가지 방법으로 채우는 경우가 존재한다. 여기서 `F(N)=F(N-2)*F(2)`를 도출해낼 수 있다. 8 | 2. F(N-4)인 상태에서 F(N)이 되기 위해 F(2)를 두 번 채우는 경우도 있으나, 그건 1에서 다뤘기 때문에 중복. 아래 그림처럼 제일 윗줄은 가로블럭, 양 옆 끝에 세로블럭, 그 사이에 가로블럭이 들어있는 타일로 채우는 방법, 또 이 모양을 뒤집어서 채우는 방법으로 두 가지가 있다. 1에서 구한 값에 `F(N-4)*2`을 더해준다. 9 | 3. F(N-6)인 상태에서도 2번과 마찬가지로 가로가 6인 타일을 뒤집어서 채우는 경우까지 고려한다. 2에서 구한 값에 `F(N-6)*2`을 더해준다. 10 | 4. 2,3을 정리해서 `F(N-K)*2(4<=K<=N, K는 4이상 짝수)`로 정리할 수 있다. 11 | 12 | ``` 13 | N이 2 이상 짝수일때 14 | F(N)=F(N-2)*F(2) 15 | +F(N-4)*2+F(N-6)*2+F(N-8)*2+…+F(2)*2+F(0)*2 16 | ``` 17 | 18 | 19 | 20 | ### 코드 21 | 22 | ```java 23 | import java.util.Scanner; 24 | 25 | public class Baekjoon2133 { 26 | public static void main(String[] args) { 27 | Scanner s = new Scanner(System.in); 28 | int N = s.nextInt(); 29 | System.out.println(groutTiles(N)); 30 | } 31 | 32 | private static int groutTiles(int n) { 33 | int[] dp = new int[n + 1]; 34 | dp[0] = 1; 35 | for (int i = 2; i <= n; i++) { 36 | dp[i] = dp[i - 2] * 3; 37 | for (int j = i-4; j >= 0; j -= 2) 38 | dp[i] += dp[j] * 2; 39 | } 40 | return dp[n]; 41 | } 42 | } 43 | 44 | ``` 45 | 46 | ### Time complexity 47 | 48 | O(N) 49 | 50 | ### Space complexity 51 | 52 | O(N) 53 | -------------------------------------------------------------------------------- /source/lukas/17032020_Greedy.md: -------------------------------------------------------------------------------- 1 | 프로그래머스 탐욕법(Greedy) 문제 2 | ================================ 3 | 4 | - 체육복 5 | - https://programmers.co.kr/learn/courses/30/lessons/42862 6 | 7 | ### 풀이 방법 8 | 9 | #### 문제 접근 방법 10 | 11 | - 체육복을 도난당한 학생들을 기준으로 여벌을 가진 학생들로부터 빌릴 수 있는지 확인 12 | - 여벌을 가진 학생들도 도난 당할 수 있으므로 두 배열 안에 중복되는 수가 존재할 수 있음 13 | - HashSet 을 이용해 중복되는 값 비교 및 추가/삭제 14 | - answer 변수는 처음 총 학생 수 - 도난 당한 학생 수로 시작 15 | 16 | #### 접근 방법을 적용한 코드 17 | 18 | ```java 19 | import java.util.HashSet; 20 | 21 | class Solution { 22 | public int solution(int n, int[] lost, int[] reserve) { 23 | int answer = n - lost.length; 24 | 25 | HashSet reservedList = new HashSet(); 26 | HashSet lostList = new HashSet(); 27 | 28 | for (int i : reserve) { 29 | reservedList.add(i); 30 | } 31 | 32 | for (int i : lost) { 33 | if(reservedList.contains(i)) { 34 | reservedList.remove(i); 35 | answer++; 36 | }else { 37 | lostList.add(i); 38 | } 39 | } 40 | 41 | for (int i : lostList) { 42 | if(reservedList.contains(i - 1)) { 43 | reservedList.remove(i - 1); 44 | answer++; 45 | }else if(reservedList.contains(i + 1)) { 46 | reservedList.remove(i + 1); 47 | answer++; 48 | } 49 | } 50 | 51 | return answer; 52 | } 53 | } 54 | ``` 55 | -------------------------------------------------------------------------------- /source/ohhako/coding test/2018_summerCoding2.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 서머코딩/윈터코딩(~2018) 탐욕법(Greedy) 문제 2 | - 예산 3 | - https://programmers.co.kr/learn/courses/30/lessons/12982 4 | 5 | 6 | ### 문제 접근 방법 7 | - 가장 많은 부서를 지원하려면 가장 적은 지원비부터 차례대로 지원해야 한다. 8 | - 부서만큼 반복 수행 9 | - 총지원비가 해당 부서의 금액을 감당할 수 있으면 지원 10 | - 지원이란, 총지원비 감소와 부서수 증감을 동반함 11 | - 총지원비가 마이너스 되면 for문 탈출(break) 12 | 13 | ### 접근 방법을 적용한 코드 14 | 1. 첫번째 코드 15 | ```java 16 | import java.util.Arrays; 17 | class Solution { 18 | public int solution(int[] d, int budget) { 19 | int answer = 0; 20 | Arrays.sort(d); 21 | for(int i=0 ; i< d.length ; i++){ 22 | if(budget-d[i]>=0){ 23 | budget-=d[i]; 24 | answer++; 25 | }else break; 26 | } 27 | 28 | return answer; 29 | } 30 | } 31 | ``` 32 | 33 | 34 | 2. 두번째 코드 35 | ```java 36 | import java.util.Arrays; 37 | class Solution { 38 | public int solution(int[] d, int budget) { 39 | int answer = 0; 40 | int i=0; 41 | Arrays.sort(d); 42 | while(budget-d[i]>=0){ 43 | budget-=d[i]; 44 | answer++; 45 | i++; 46 | if(!(i=n){ 40 | if(mid q = new LinkedList<>(); 30 | PriorityQueue pq = new PriorityQueue<>(Collections.reverseOrder()); 31 | 32 | for(int i=0; i 0){ 51 | location--; 52 | } else { 53 | location = q.size() - 1; 54 | } 55 | } 56 | 57 | return answer; 58 | } 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /source/lukas/04032020_TowerStack.md: -------------------------------------------------------------------------------- 1 | 프로그래머스 스택/큐 문제 2 | ========================= 3 | 4 | - 타워 5 | - https://programmers.co.kr/learn/courses/30/lessons/42588 6 | 7 | ### 풀이 방법 8 | 9 | #### 문제 접근 방법 10 | 11 | - 수신하는 탑은 언제나 송신하는 탑의 왼쪽에 위치하며 수신된 신호는 다시 송신되지 않는다 12 | - 배열에 두개의 포인터 (두개의 for문) 를 이용해 구현 가능 하나 LIFO의 Stack 구조를 활용하여 문제를 풀 수 있다. 13 | - 스택에 들어가는 Tower 클래스를 만들어 탑의 index와 height를 저장 14 | 15 | #### 접근 방법을 적용한 코드 16 | 17 | ```java 18 | import java.util.Stack; 19 | 20 | class Solution { 21 | class Tower { 22 | int index; 23 | int height; 24 | 25 | public Tower(int index, int height) { 26 | this.index = index; 27 | this.height = height; 28 | } 29 | } 30 | 31 | public int[] solution(int[] heights) { 32 | 33 | Stack st = new Stack<>(); 34 | int[] answer = new int[heights.length]; 35 | 36 | for (int i = 0; i < heights.length; i++) { 37 | 38 | Tower tower = new Tower(i + 1, heights[i]); 39 | int receiverIndex = 0; 40 | 41 | while (!st.isEmpty()) { 42 | Tower left = st.peek(); 43 | 44 | if (left.height > tower.height) { 45 | receiverIndex = left.index; 46 | break; 47 | } 48 | 49 | st.pop(); 50 | } 51 | 52 | st.push(tower); 53 | answer[i] = receiverIndex; 54 | } 55 | 56 | return answer; 57 | } 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /source/ohhako/boj/bj_1018.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main{ 3 | public static void main(String[] args){ 4 | 5 | Scanner sc = new Scanner(System.in); 6 | int n= sc.nextInt(); 7 | int m= sc.nextInt(); 8 | String[] row = new String[m]; 9 | sc.nextLine(); 10 | 11 | for(int i=0 ; i repaint = new ArrayList<>(); 17 | for(int i=0 ; i<=m-8 ; i++){ //오른쪽 이동 횟수 18 | for(int j=0 ; j<=n-8 ; j++){ //아래쪽 이동 횟수 19 | int s1_count = 0; //기준과 다른 갯수 20 | int s2_count = 0; 21 | for(int p=0 ; p<8 ; p++){ //행 범위 22 | String line = row[p+j]; //가로 한줄 가져옴 23 | for(int k=0 ; k<8 ; k++){ 24 | if(line.charAt(k+i)!=s3[p%2][(k+i)%2]) 25 | s1_count++; 26 | if(line.charAt(k+i)!=s3[p%2][(k+i)%2]) 27 | s2_count++; 28 | } 29 | } 30 | repaint.add(Math.min(s1_count,s2_count)); 31 | } 32 | } 33 | 34 | int min = repaint.get(0); 35 | for(int i=1;irepaint.get(i)) 37 | min = repaint.get(i); 38 | } 39 | System.out.println(min); 40 | } 41 | } -------------------------------------------------------------------------------- /docs/java/String사용클래스비교.md: -------------------------------------------------------------------------------- 1 | # String, StringBuffer, StringBuilder 비교하기 2 | String, StringBuffer, StringBuilder 는 모두 String 문자열을 저장하고 관리하는 클래스 입니다. 쓰임새에 따라 String 클래스를 선택해서 사용 할 수 있으며 어떤 상황에서 어떤 String클래스를 이용하면 좋을지 알아보겠습니다. 3 | 4 | ### 차이점 요악 설명 5 | - String은 불변(immutable) 속성이다 6 | - StringBuffer는 가변(mutable) 속성이다 7 | - 짧은 문자열을 더하는 경우엔 String 사용 8 | - 스레드에 안전한 프로그램 개발 시 StringBuffer 사용 9 | - 스레드 안전여부가 관계 없을 시 StringBuilder 사용 10 | - 연산이 많아지는 경우 StringBuilder > StringBuffer >>> String 11 | 12 | ### 자바 메모리 공간 구조 13 | ![img load fail](./img/java_memory.jpg) 14 | 출처:ohhako 15 | 16 | ### String 클래스 17 | - String 객체가 한번 생성되면 **할당된 메모리 공간**은 **변하지 않는다.** 18 | - concat이나 더하기 연산 이용시 새로운 객체를 생성해 그 객체를 참조한다. 19 | - 즉 한번 생성된 객체의 내용은 변하지 않음 20 | - 참조 객체가 변경되는 것 21 | - 참조되지 않는 객체는 가비지컬렉터로부터 수거됨 22 | - 새 객체는 Heap영역에 생성된다. 23 | - 새 객체 참조방식 때문에 Heap에 데이터가 쌓이면 문자열이 많은 경우 메모리 부족으로 속도가 느려진다. 24 | 25 | ### StringBuffer 클래스, StringBuilder 클래스 26 | #### 공통점 27 | - 문자열 연산, 추가시에 기존 버퍼의 크기를 늘려준다. 28 | - 따라서 String보다 동작 방식이 유연하다. 29 | - Buffer, Builder가 제공하는 메서드는 동일하다. 30 | #### 차이점 31 | - StringBuffer는 각 메서드마다 Synchronized Keyword가 존재한다. 32 | - 멀티스레드 환경에서 사용하기 좋다. 33 | - 동기화 지원 34 | - Builder는 싱글스레드 환경에서 사용하기 좋다. 35 | - 동기화를 지원하되 보장하지 않음 36 | 37 | 38 | 39 | 40 | --- 41 | 본 글은 아래의 사이트를 참고해 작성되었습니다. 42 | - https://yaboong.github.io/java/2018/05/26/java-memory-management/ 43 | - https://dsnight.tistory.com/50 44 | - https://coding-factory.tistory.com/127 45 | - https://12bme.tistory.com/42 46 | - https://zzdd1558.tistory.com/144 -------------------------------------------------------------------------------- /source/lee/200312_priorityQueue2.md: -------------------------------------------------------------------------------- 1 | # 라면공장 2 | - https://programmers.co.kr/learn/courses/30/lessons/42629 3 | 4 | ## 문제 접근 방법 5 | 문제 설명은 이해했는데 공통적인 접근 방법을 전혀 떠올리지 못했다. 다른사람 코드 보고 공부함 6 | 1. 오늘(`elapsedDate=0`) 부터 k일까지 재고를 하나씩 소진해감. 7 | 2. 갖고 있는 재고가 0이 된다면, `dates[fromDateIdx]`부터 `elapsedDate`까지 들어온 공급을 `stocksPq`에 후보군으로써 넣어놓음 8 | 3. `pq.poll()`을 하게 되면 자동으로 공급된 재고 중 최댓값이 반환된다. 이 값을 stock에 더하고 다시 하루씩 재고를 소진한다. 9 | 10 | ## 코드 구현 11 | ```java 12 | import java.util.*; 13 | 14 | class Solution { 15 | public int solution(int stock, int[] dates, int[] supplies, int k) { 16 | int answer = 0; 17 | PriorityQueue stocksPq = new PriorityQueue<>(Collections.reverseOrder()); 18 | int fromDateIdx = 0; 19 | //k 전날 까지 버텨야 함. 20 | for (int elapsedDate = 1; elapsedDate < k; elapsedDate++) { 21 | // 매일 그 날 재고를 쓴다. 22 | stock--; 23 | 24 | //가지고 있는 stock이 그날 떨어진다면, elapsedDate전에 들어온 공급을 stocksPq에 후보군으로써 넣어놓음 25 | if (stock == 0) { 26 | while (fromDateIdx < dates.length && dates[fromDateIdx] <= elapsedDate) { 27 | stocksPq.offer(supplies[fromDateIdx]); 28 | fromDateIdx++; 29 | } 30 | 31 | answer++; 32 | // pq에서 최댓값 하나(가장 긴 날을 버틸 수 있는 재고량)만 현재 재고에 더함. 33 | stock += stocksPq.poll(); 34 | } 35 | } 36 | return answer; 37 | } 38 | } 39 | 40 | ``` 41 | 42 | ### Time complexity 43 | O(n\*k) n=dates.length 44 | 45 | ### Space complexity 46 | O(n) n=dates.length 47 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj10830.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | typedef long long LL; 8 | 9 | int N; 10 | LL B; 11 | 12 | vector> answer(6, vector(6)); 13 | vector> matrix(6, vector(6)); 14 | 15 | vector> mulMaxrix(vector>matrix1, vector>matrix2) 16 | { 17 | vector>mul(6, vector(6)); 18 | 19 | for (int i = 1; i <= N; i++) 20 | { 21 | for (int j = 1; j <= N; j++) 22 | { 23 | LL SUM = 0; 24 | 25 | for (int k = 1; k <= N; k++) 26 | SUM += (matrix1[i][k] * matrix2[k][j]); 27 | 28 | mul[i][j] = SUM; 29 | mul[i][j] %= 1000; 30 | } 31 | } 32 | return mul; 33 | } 34 | 35 | void init() 36 | { 37 | cin >> N >> B; 38 | 39 | for (int i = 1; i <= N; i++) 40 | { 41 | for (int j = 1; j <= N; j++) 42 | { 43 | cin >> matrix[i][j]; 44 | 45 | if (i == j) { 46 | answer[i][j] = 1; 47 | } 48 | } 49 | } 50 | } 51 | 52 | void solve() 53 | { 54 | while (B > 0) 55 | { 56 | if (B % 2 != 0) 57 | answer = mulMaxrix(answer, matrix); 58 | 59 | matrix = mulMaxrix(matrix, matrix); 60 | B /= 2; 61 | } 62 | } 63 | 64 | void print() 65 | { 66 | for (int i = 1; i <= N; i++) 67 | { 68 | for (int j = 1; j <= N; j++) 69 | { 70 | cout << answer[i][j] << " "; 71 | } 72 | cout << "\n"; 73 | } 74 | } 75 | 76 | int main() 77 | { 78 | ios_base::sync_with_stdio(0); 79 | cout.tie(0); 80 | cin.tie(0); 81 | 82 | init(); 83 | solve(); 84 | print(); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /source/kim-dabin/BJ_14501.md: -------------------------------------------------------------------------------- 1 | # [백준/자바]14501번 퇴사 2 | 3 | https://www.acmicpc.net/problem/14501 4 | 5 | 6 | 7 | ## 입력 데이터 8 | 9 | - N(1 ≤ N ≤ 15) : 근무 기간 10 | - T_i(1 ≤ T_i ≤ 5) : i일의 상담을 완료할 때까지 걸리는 시간 11 | - P_i(1 ≤ P_i ≤ 1,000) : i일의 상담을 완료할 때, 받을 수 있는 액수 12 | 13 | 14 | 15 | ## 접근 방식 16 | 17 | - 1 ~ N일 까지 상담해서 N+1에 정산 받을 때까지, 1 ~ T[i] (1 <= i <= N)의 최대 수익을 구함 18 | - dp[i] = (1 ~ i날 까지) 최대 수익 19 | 20 | 21 | 22 | 1. 1 ~ (i-1)까지 상담 일정이 있고 그에 해당하는 수익이 최대 수익이라면 dp[i]에 넣음 23 | 1. 수익은 이전에 벌어들인, 최대 수익과 합산해서 넣음 24 | 2. 상담 일정이 없다면, 이제까지의 최대 수익을 해당 dp[i]에 넣음 25 | 3. 퇴사일자인, N+1이 되면 이제까지 합산한 최대 수익(dp[N])을 return 26 | 27 | 28 | 29 | ## 소스 구현 30 | 31 | ```java 32 | import java.io.BufferedReader; 33 | import java.io.InputStreamReader; 34 | 35 | public class BJ14501 { 36 | public static void main(String[] args) throws Exception { 37 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 38 | int N = Integer.parseInt(br.readLine()); // 근무 일 39 | int[] T = new int[N+2]; // 상담 완료까지 시간 40 | int[] P = new int[N+2]; //상담 금액 41 | int[] dp = new int[N+2]; 42 | for(int i=1; i<=N;i++) { 43 | String[] str = br.readLine().split(" "); 44 | T[i]= Integer.parseInt(str[0]); 45 | P[i]=Integer.parseInt(str[1]); 46 | } 47 | 48 | for(int i=1; i<=N+1; i++) {//1 ~ N+1 49 | for(int j=1; j 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | typedef pair Pair; 12 | 13 | int N, K; 14 | int visited[100001]; 15 | int step[100001]; 16 | int answer_time; 17 | int answer_count; 18 | 19 | void bfs() 20 | { 21 | queueq; 22 | q.push(Pair(0, N)); 23 | visited[N] = 1; 24 | 25 | while (q.empty() != true) 26 | { 27 | Pair ret = q.front(); 28 | q.pop(); 29 | 30 | int time = ret.first; 31 | int pos = ret.second; 32 | 33 | if (pos == K) { 34 | answer_time = time; 35 | answer_count++; 36 | } 37 | 38 | for (int i = 1; i <= 3; i++) 39 | { 40 | int next1 = pos; 41 | 42 | switch (i) 43 | { 44 | case 1: 45 | { 46 | next1--; 47 | break; 48 | } 49 | case 2: 50 | { 51 | next1++; 52 | break; 53 | } 54 | case 3: 55 | { 56 | next1 *= 2; 57 | break; 58 | } 59 | } 60 | 61 | if (next1 < 0 || next1>100000) 62 | continue; 63 | 64 | if (visited[next1] == 0) 65 | { 66 | q.push(Pair(time + 1, next1)); 67 | visited[next1] = 1; 68 | step[next1] = step[pos] + 1; 69 | } 70 | else if (step[pos] + 1 == step[next1]) { 71 | q.push(Pair(time + 1, next1)); 72 | } 73 | } 74 | } 75 | } 76 | 77 | int main() 78 | { 79 | ios_base::sync_with_stdio(0); 80 | cout.tie(0); 81 | cin.tie(0); 82 | 83 | cin >> N >> K; 84 | bfs(); 85 | cout << answer_time << endl; 86 | cout << answer_count<< endl; 87 | return 0; 88 | } -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1062.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int N, K; 10 | vectorvoca; 11 | int visited[26]; 12 | int answer; 13 | 14 | void init() 15 | { 16 | cin >> N >> K; 17 | 18 | for (int i = 0; i < N; i++) { 19 | string str; 20 | cin >> str; 21 | string sub_str = ""; 22 | for (int j = 4; j < str.length() - 4; j++) sub_str += str[j]; 23 | voca.push_back(sub_str); 24 | } 25 | 26 | visited['a' - 'a'] = 1; 27 | visited['n' - 'a'] = 1; 28 | visited['t' - 'a'] = 1; 29 | visited['i' - 'a'] = 1; 30 | visited['c' - 'a'] = 1; 31 | } 32 | 33 | int getCntOfRead() 34 | { 35 | int ret = 0; 36 | 37 | for (int i = 0; i < voca.size(); i++) 38 | { 39 | bool flag = false; 40 | 41 | for (auto item : voca[i]) 42 | { 43 | if (visited[item - 'a'] == 0) 44 | { 45 | flag = true; 46 | break; 47 | } 48 | } 49 | if (!flag) ret++; 50 | } 51 | 52 | return ret; 53 | } 54 | 55 | void dfs(int idx, int cnt) 56 | { 57 | if (cnt >= K - 5) 58 | { 59 | answer = max(answer, getCntOfRead()); 60 | return; 61 | } 62 | 63 | for (int i = idx + 1; i < 26; i++) { 64 | if (visited[i]) 65 | continue; 66 | 67 | visited[i] = 1; 68 | dfs(i, cnt + 1); 69 | visited[i] = 0; 70 | } 71 | } 72 | 73 | int main() 74 | { 75 | ios_base::sync_with_stdio(0); 76 | cout.tie(0); 77 | cin.tie(0); 78 | 79 | init(); 80 | 81 | if (K == 26) { 82 | answer = N; 83 | } 84 | else if (K >= 5) { 85 | dfs(-1, 0); 86 | } 87 | cout << answer << endl; 88 | return 0; 89 | } -------------------------------------------------------------------------------- /contents/search요약.md: -------------------------------------------------------------------------------- 1 | # 탐색방법 요약 2 | 3 | ### 완전탐색 (Brute-force) 4 | 빠른 cpu를 이용해 가능한 경우의 수를 모두 나열하여 답을 찾는 방법이다. 가능한 방법을 전부 만들어 무식하게 푸는 알고리즘이다. 5 | 6 | - **BF 문제 목록** 7 | - [소수찾기](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200227_BF.md) 8 | - [모의고사](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200128_%EC%99%84%EC%A0%84%ED%83%90%EC%83%89.md) 9 | - [일곱난쟁이](https://www.acmicpc.net/problem/2309) 10 | - [boj 분해합](https://www.acmicpc.net/problem/2231) 11 | - [boj 모든순열](https://www.acmicpc.net/problem/10974) 12 | - [boj 차이를 최대로](https://www.acmicpc.net/problem/10819) 13 | - [boj 로또](https://www.acmicpc.net/problem/6603) 14 | 15 | ### 탐욕법 (greedy 탐색) 16 | 매순간 최적이라고 생각되는 것을 선택해 나가는 방식이다. 그리디 알고리즘을 풀 때 중요 포인트는 '어떤 기준으로' 탐욕적인 선택을 하느냐 이다. 17 | 1. 답 내는 과정 여러부분으로 나누기 18 | 2. 탐욕적 선택 기준 정하기 19 | 3. 탐욕적 선택 속성, 최적 부분 구조 따져보기 20 | - [탐욕법 알고리즘 정리글 참고](https://github.com/TheCopiens/algorithm-study/blob/master/contents/greedy.md) 21 |
22 | 23 | - **탐욕법 문제 목록** 24 | - 배낭문제 25 | - [체육복](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200202_greedy.md) 26 | - 최소부분해(체육복 있는 학생)/다음 부분해(체육복 없지만 여분있는)/다음 부분해(앞뒤로 체육복 빌리는 학생) 27 | - [큰수만들기](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200228_greedy.md) 28 | - [조이스틱](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/200303_greedy.md) 29 | - 해 구하는 방법을 네가지로 나눈다. (위아래 이동/우로 이동/좌로이동/우로 이동하다 되돌아와 좌로 이동) 30 | - [예산](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/coding%20test/2018_summerCoding2.md) 31 | - '가장 금액이 낮은 지원비'는 탐욕적 선택 속성이며 본 문제는 최적 부분 구조를 만족한다 -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1389.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | typedef pair Pair; 14 | 15 | int N, M; 16 | vectorGP[1001]; 17 | int visited[1001]; 18 | int step[1001]; 19 | 20 | void init() 21 | { 22 | cin >> N >> M; 23 | 24 | for (int i = 0; i < M; i++) 25 | { 26 | int a, b; 27 | cin >> a >> b; 28 | GP[a].push_back(Pair(b, 1)); 29 | GP[b].push_back(Pair(a, 1)); 30 | } 31 | } 32 | 33 | void bfs(int start) 34 | { 35 | queueq; 36 | q.push(start); 37 | visited[start] = 1; 38 | 39 | while (q.empty() != true) 40 | { 41 | int pos = q.front(); 42 | q.pop(); 43 | 44 | for (auto elem : GP[pos]) 45 | { 46 | int next = elem.first; 47 | 48 | if (visited[next] == 0) 49 | { 50 | q.push(next); 51 | visited[next] = 1; 52 | step[next] = step[pos] + 1; 53 | } 54 | } 55 | } 56 | } 57 | 58 | int main() 59 | { 60 | ios_base::sync_with_stdio(0); 61 | cout.tie(0); 62 | cin.tie(0); 63 | 64 | init(); 65 | 66 | int MIN = 2e9; 67 | vectorSUM(N + 1, 0); 68 | 69 | for (int i = 1; i <= N; i++) 70 | { 71 | bfs(i); 72 | for (int j = 1; j <= N; j++) SUM[i] += step[j]; 73 | memset(visited, 0, sizeof(visited)); 74 | memset(step, 0, sizeof(step)); 75 | } 76 | 77 | int answer = 0; 78 | 79 | for (int i = N; i >= 1; i--) { 80 | if (SUM[i] <= MIN) { 81 | answer = i; 82 | MIN = SUM[i]; 83 | } 84 | } 85 | 86 | cout << answer << endl; 87 | return 0; 88 | } -------------------------------------------------------------------------------- /source/woodi/201101_Programmers_43105.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 DP 문제 2 | - 정수 삼각형 3 | - https://programmers.co.kr/learn/courses/30/lessons/43105 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | 8 | 9 | ### 문제 접근 방법 10 | - 왜 DP? 11 | 최댓값을 구하는 과정에서 특정 원소를 반복해서 거쳐가게 된다. 12 | d[i-1][j-1] d[i-1][j] 13 | d[i][j-1] d[i][j] d[i][j+1] 14 | d[i][j]를 구하는 방법은 2가지 : d[i-1][j-1]에서 오는 경우, d[i-1][j]에서 오는 경우 15 | 둘 중 더 큰 값을 저장해야 이후에도 최대 값이 저장되게 된다. 16 | ### 구현 배경 지식 17 | - DP 18 | ### 접근 방법을 적용한 코드 19 | ```java 20 | import java.util.*; 21 | class Solution { 22 | public int solution(int[][] triangle) { 23 | int answer = 0; 24 | int[][] d = new int[triangle.length][]; // [i][j] 위치의 원소에 도달했을때 총 합 중에 가장 큰 값 -> 이후 d[lastidx] 중 가장 큰 값이 answer이다 25 | 26 | for(int i=0; i= k) { 63 | // 돌의 높이 == 친구들의 인원인 경우 연속해서 k개 64 | return false; 65 | } 66 | } 67 | return true; 68 | } 69 | } 70 | ``` 71 | -------------------------------------------------------------------------------- /source/woodi/20200915_boj_2294.md: -------------------------------------------------------------------------------- 1 | # 백준 DP 문제 2 | - 동전2 3 | - https://www.acmicpc.net/problem/2294 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - n가지 종류의 동전이 있다. 이 동전들을 적당히 사용해서, 그 가치의 합이 k원이 되도록 하고 싶다. 그러면서 동전의 개수가 '최소'가 되도록 하려고 한다. 각각의 동전은 몇 개라도 사용할 수 있다. 8 | - [제한 조건] 9 | - (1 ≤ n ≤ 100, 1 ≤ k ≤ 10,000) 10 | - 동전의 가치는 100,000보다 작거나 같은 자연수이다 11 | 12 | ### 문제 접근 방법 13 | - {k-(마지막 동전)} + (마지막 동전) = k 14 | - d[k] : k원을 만들 수 있는 동전의 최소 개수 15 | - d[k] = d[k-(마지막 동전의 값)] + 1 16 | 17 | ### 구현 배경 지식 18 | - DP (memoization) 19 | 20 | ### 접근 방법을 적용한 코드 21 | ```java 22 | import java.util.Scanner; 23 | 24 | public class solution { 25 | public static void main(String[] args) { 26 | Scanner sc = new Scanner(System.in); 27 | int n = sc.nextInt(); 28 | int k = sc.nextInt(); 29 | int[] a= new int[n]; // 동전의 종류 30 | int[] d = new int[100001]; // k원을 만들 수 있는 최소 개수 memoization 31 | 32 | for(int i=0; i0) { 39 | int temp = d[i-a[j]]; 40 | if(temp < 1) { 41 | continue; 42 | }else { 43 | if(d[i]<1) { 44 | d[i] = temp+1; 45 | }else { 46 | d[i] = d[i] > temp+1 ? temp+1 : d[i]; 47 | } 48 | } 49 | } 50 | } 51 | } 52 | int answer; 53 | if(d[k]<1) { 54 | answer = -1; 55 | }else { 56 | answer = d[k]; 57 | } 58 | System.out.println(answer); 59 | } 60 | } 61 | 62 | ``` 63 | 64 | ### 느낀점 65 | - 처음에는 재귀함수를 이용해서 풀려고 했으나 시간 초과 뜸 66 | - DP문제는 memoization을 통해 시간을 단축시킨다. 67 | - bottom up 방식이 DP문제 풀기에 조금더 편했다. -------------------------------------------------------------------------------- /solution example.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 DP 문제 2 | - 2xn 타일링 3 | - https://programmers.co.kr/learn/courses/30/lessons/12900 4 | 5 | ### 문제 이해하기 6 | - 입력값: 가로길이 n 7 | - 가로2 세로1 길이의 타일로 가로n 세로2의 바닥을 가득 채워야 한다. 8 | - 타일 하나는 가로 배치, 세로 배치 두 가지를 할 수 있다. 9 | - 출력값: 만들 수 있는 타일 패턴의 개수 10 | 11 | ### 문제 접근 방법 12 | - 가로 길이가 1씩 늘어날때 마다 추가되는 타일의 모양을 직접 손수 그려 확인한다. 13 | - dp[i ]: 가로 길이가 i일때 배치 가능한 바닥의 개수 14 | - i 바닥 개수는 i-1 바닥의 오른쪽에 1x2 타일을 붙인 개수 d[n-1 ]를 포함한다. 15 | - 그 외에 새로 추가되는 바닥이 있다. 바닥의 맨 오른쪽 끝 가로2의 부분을 가로2 세로1 타일 두개로 채울 수 있는 것이다. 16 | - 위 패턴의 개수는 i-2까지 바닥 개수에 하나의 패턴을 추가하므로 d[n-2 ]를 포함한다. 17 | - `제한사항`을 제대로 확인해야 한다. 반복문을 수행하며 값이 커질 수 있으니 1,000,000,007으로 나눈 나머지 값을 저장해야 했다. 18 | 19 | ### 구현 배경 지식 20 | - 메모라이징 기법 DP 21 | 22 | ### 문제를 해결한 코드 23 | 24 | ```java 25 | class Solution { 26 | public int solution(int n) { 27 | int[] dp = new int[n+1]; 28 | dp[0] = 1; 29 | dp[1] = 1; 30 | for(int i=2 ; i<=n ; i++){ 31 | dp[i] = (dp[i-1]+dp[i-2])%1000000007; 32 | } 33 | return dp[n]%1000000007; 34 | } 35 | } 36 | ``` 37 | 38 | ### 못풀었던 이유 39 | 40 | - 가로2,세로1 두개가 추가되는 타일이 이전에 저장한 바닥 갯수가 아닌 상수 k개 대로 늘어나는 줄 알았다. 41 | - 하지만 i=6 부터는 그림을 직접 그리는게 부담스러워 졌다. 42 | - 문제에서 주어진 그림은 n=4 이다. `n=4 까지 그리면서 패턴을 파악하라. 그 이상은 갈 필요가 없다` 는 의도같다. 43 | 44 | 45 | i를 1씩 늘리며 순서대로 진행할 때 이전 타일에서 안보였던 패턴이 등장했다. 그래서 홀수/짝수로 나누어 풀어보았다. 처음에 나왔던 식은 아래와 같았다. 그리고 테스트 케이스에서 통과하지 못해서 n=5를 그려봤는데 새로운 패턴이 3개나 늘어난걸 확인했다. 46 | 47 | ```java 48 | if(i%2==0) 49 | dp[i] = dp[i-1] + dp[i-2]; 50 | else 51 | dp[i] = dp[i-1] + 1; 52 | ``` 53 | 54 | ### 문제를 해결한 방법 55 | - 새로 늘어나는 타일에 따라 새로 생겨나는 패턴의 규칙을 찾는게 관건이였다. 56 | - 새로운 타일 규칙은 이중for문에서 연산 57 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/숨바꼭질5.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #define LIMIT 500000 8 | 9 | using namespace std; 10 | 11 | typedef pair Pair; 12 | 13 | int N, K; 14 | int answer = -1; 15 | vector>dist(LIMIT+1, vector(2, -1)); 16 | 17 | void init() 18 | { 19 | cin >> N >> K; 20 | } 21 | 22 | void bfs() 23 | { 24 | queueq; 25 | q.push(Pair(0, N)); 26 | dist[N][0] = 0; 27 | 28 | while (q.empty() != true) 29 | { 30 | Pair elem = q.front(); 31 | q.pop(); 32 | 33 | int time = elem.first; 34 | int pos = elem.second; 35 | int flag = ++time % 2 == 0 ? 0 : 1; 36 | 37 | for (auto next : { pos - 1,pos + 1,pos * 2 }) 38 | { 39 | if (next<0 || next>LIMIT || dist[next][flag] >= 0) 40 | continue; 41 | 42 | q.push(Pair(time, next)); 43 | dist[next][flag] = time; 44 | } 45 | } 46 | } 47 | 48 | void solve() 49 | { 50 | int time = 0; 51 | int pos = K; 52 | 53 | while (pos <= LIMIT) 54 | { 55 | if (dist[pos][0] >= 0 && time >= dist[pos][0]) 56 | { 57 | if ((time - dist[pos][0]) % 2 == 0) 58 | { 59 | cout << time << endl; 60 | return; 61 | } 62 | } 63 | 64 | if (dist[pos][1] >= 0 && time >= dist[pos][1]) 65 | { 66 | if ((time - dist[pos][1]) % 2 == 0) 67 | { 68 | cout << time << endl; 69 | return; 70 | } 71 | } 72 | pos += ++time; 73 | } 74 | cout << -1 << endl; 75 | } 76 | 77 | int main() 78 | { 79 | ios_base::sync_with_stdio(0); 80 | cout.tie(0); 81 | cin.tie(0); 82 | 83 | init(); 84 | bfs(); 85 | solve(); 86 | return 0; 87 | } -------------------------------------------------------------------------------- /source/lee/team/20200503_로또.md: -------------------------------------------------------------------------------- 1 | # 로또 2 | 3 | https://www.acmicpc.net/problem/6603 4 | 5 | ## 문제 접근 방법 6 | 7 | dfs&backtracking 8 | 9 | - 제일 처음 시작 가능한 수: `s[0]`부터 `s[k-6]`까지 10 | - 모든 경우의 수를 찾는 것이기 때문에 dfs 11 | - 한 경우의 수를 찾고 다시 되돌아가야하기 때문에 backtracking으로 원래 상태로 돌려놓음 12 | 13 | 14 | ### 코드 15 | 16 | ```java 17 | import java.util.Scanner; 18 | 19 | public class Baekjoon6603 { 20 | public static void main(String[] args) { 21 | Scanner scanner = new Scanner(System.in); 22 | int k; 23 | do { 24 | k = scanner.nextInt(); 25 | int[] s = new int[k]; 26 | for (int i = 0; i < k; i++) { 27 | s[i] = scanner.nextInt(); 28 | } 29 | 30 | for (int j = 0; j <= k - 6; j++) { 31 | StringBuilder result = new StringBuilder().append(s[j]).append(" "); 32 | dfs(s, j+1, 1, result); 33 | } 34 | System.out.println(); 35 | } while (k != 0); 36 | 37 | } 38 | 39 | private static void dfs(int[] s, int idx, int cnt, StringBuilder result) { 40 | if (cnt == 6) { 41 | System.out.println(result.toString()); 42 | return; 43 | } 44 | 45 | for (int i=idx;i 6 | 7 | ## 깃허브 웹에서 브랜치(branch) 만드는 방법 8 | ![img load fail](./imgs/createBranch1.JPG)
9 | 1. 원하는 저장소에 들어가기 10 | 2. 메뉴 왼쪽 하단에 보면 셀렉박스로 branch master라고 써있는 버튼 확인 11 | 3. 버튼 클릭 시 현재 원격저장소가 갖고있는 브랜치 목록이 뜬다. 12 | 4. 텍스트박스를 클릭해 브랜치이름을 입력한다. 13 | 5. Enter 치면 branch 생성 완료 14 | 6. 위 5개의 메뉴에서 commits 오른쪽에 있는 branches를 클릭하면 생성된 브랜치를 확인할 수 있다. 15 | 16 | 참고로 웹에서 생성한 브랜치를 노트북으로 가져오는 작업은 아래 링크를 따라 시행한다. 17 | - [GitBash를 이용해 깃허브 원격 저장소 브랜치 가져오는 방법](https://github.com/TheCopiens/algorithm-study/blob/master/docs/github/bring_remote_branch.md#gitbash%EB%A5%BC-%EC%9D%B4%EC%9A%A9%ED%95%B4-%EA%B9%83%ED%97%88%EB%B8%8C-%EC%9B%90%EA%B2%A9-%EC%A0%80%EC%9E%A5%EC%86%8C-%EB%B8%8C%EB%9E%9C%EC%B9%98-%EA%B0%80%EC%A0%B8%EC%98%A4%EB%8A%94-%EB%B0%A9%EB%B2%95) 18 | 19 | 20 | ## GitBash 이용해 브랜치(branch) 만드는 방법 21 | 22 | 1. 작업폴더에서 GitBash 오픈 (Windows경우 파란색 글씨의 master표시 확인) 23 | 2. git branch 브랜치이름 24 | - 브랜치 생성 25 | 3. git checkout 브랜치이름 26 | - 생성한 브랜치로 전환 27 | - 2번의 브랜치이름과 동일해야 한다. 28 | 29 | 4. git push origin 브랜치이름 30 | - 원격 저장소에 반영하기 31 | - 2,3의 브랜치이름과 동일해야 한다. 32 | 33 | 34 | 참고로 1,2번의 작업을 동시에 진행하는 명령어는 아래와 같다.
35 | git checkout -b 브랜치이름
36 | 브랜치를 생성했으니 이제 작업 후 원격 저장소에 반영하는 작업은 아래 링크를 따라 진행한다. 37 | 38 | - [GitBash 명령어 사용 방법](https://github.com/TheCopiens/algorithm-study#gitbash-%EB%AA%85%EB%A0%B9%EC%96%B4-%EC%82%AC%EC%9A%A9-%EB%B0%A9%EB%B2%95) -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj1339(단어수학-완탐).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | int N; 11 | vector alphabets; 12 | vectorvoca_list; 13 | bool visited[10]; 14 | int hash_map[100]; 15 | int alphabet_len; 16 | long long answer; 17 | 18 | void init() 19 | { 20 | maphash_map; 21 | cin >> N; 22 | 23 | for (int i = 0; i < N; i++) 24 | { 25 | string str; 26 | cin >> str; 27 | voca_list.push_back(str); 28 | 29 | for (int j = 0; j < str.length(); j++) { 30 | if (hash_map.count(str[j]) == 0) { 31 | hash_map[str[j]] = 1; 32 | alphabets.push_back(str[j]); 33 | } 34 | } 35 | } 36 | alphabet_len = alphabets.size(); 37 | } 38 | 39 | void solve(int idx) 40 | { 41 | if (idx >= alphabet_len) 42 | { 43 | long long SUM = 0; 44 | 45 | for (int i = 0; i < voca_list.size(); i++) 46 | { 47 | long long temp_sum = 0; 48 | 49 | for (int j = 0; j < voca_list[i].size(); j++) 50 | { 51 | temp_sum += hash_map[voca_list[i][j]]; 52 | temp_sum *= 10; 53 | } 54 | SUM += temp_sum; 55 | } 56 | answer = max(answer, SUM); 57 | return; 58 | } 59 | 60 | for (int i = 0; i <= 9; i++) 61 | { 62 | if (visited[i]) continue; 63 | hash_map[alphabets[idx]] = i; 64 | visited[i] = 1; 65 | solve(idx + 1); 66 | hash_map[alphabets[idx]] = 0; 67 | visited[i] = 0; 68 | } 69 | } 70 | 71 | int main() 72 | { 73 | ios_base::sync_with_stdio(false); 74 | cout.tie(0); 75 | cin.tie(0); 76 | init(); 77 | solve(0); 78 | cout << answer / 10 << endl; 79 | return 0; 80 | } -------------------------------------------------------------------------------- /source/kim-dabin/BJ_11403.md: -------------------------------------------------------------------------------- 1 | # 백준 경로 찾기 2 | 3 | ## 문제 접근 4 | 5 | - 가중치 없는 방향 그래프 6 | - BFS로 접근 7 | 8 | 9 | 10 | ## 코드 구현 11 | 12 | ```java 13 | import java.io.*; 14 | import java.util.*; 15 | 16 | public class Main { 17 | static int[][] map; 18 | static int n; 19 | static boolean[]visited; 20 | static int[][] resMap; 21 | 22 | public static void bfs(int s) { 23 | Queue q = new LinkedList(); 24 | q.add(s); 25 | while (!q.isEmpty()) { 26 | int ver = q.poll();// 정점 27 | 28 | for (int i = 0; i < n; i++) { 29 | if (map[ver][i] == 1 && !visited[i]) { 30 | visited[i] = true; 31 | resMap[s][i] = 1; 32 | q.add(i); 33 | } 34 | // if(map[ver][i] == 1 ) { 35 | // resMap[s][i] = 1; 36 | // } 37 | 38 | } 39 | 40 | }//while end 41 | } 42 | 43 | public static void main(String[] args) throws NumberFormatException, IOException { 44 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 45 | 46 | n = Integer.parseInt(br.readLine()); 47 | map = new int[n][n]; 48 | visited = new boolean[n]; 49 | resMap = new int[n][n]; 50 | 51 | for (int i = 0; i < n; i++) { 52 | String[] str = br.readLine().split(" "); 53 | for (int j = 0; j < n; j++) { 54 | map[i][j] = Integer.parseInt(str[j]); 55 | } 56 | } // for end 57 | 58 | for (int i = 0; i < n; i++) { 59 | bfs(i); 60 | Arrays.fill(visited, false); 61 | } // for end 62 | 63 | // print the map 64 | for (int[] ma : resMap) { 65 | for (int m : ma) { 66 | System.out.print(m + " "); 67 | } 68 | System.out.println(); 69 | } 70 | 71 | } 72 | } 73 | 74 | ``` 75 | 76 | -------------------------------------------------------------------------------- /source/kim-dabin/java_BJ11403.md: -------------------------------------------------------------------------------- 1 | # 백준 경로 찾기 2 | 3 | ## 문제 접근 4 | 5 | - 가중치 없는 방향 그래프 6 | - BFS로 접근 7 | 8 | 9 | 10 | ## 코드 구현 11 | 12 | ```java 13 | import java.io.*; 14 | import java.util.*; 15 | 16 | public class Main { 17 | static int[][] map; 18 | static int n; 19 | static boolean[]visited; 20 | static int[][] resMap; 21 | 22 | public static void bfs(int s) { 23 | Queue q = new LinkedList(); 24 | q.add(s); 25 | while (!q.isEmpty()) { 26 | int ver = q.poll();// 정점 27 | 28 | for (int i = 0; i < n; i++) { 29 | if (map[ver][i] == 1 && !visited[i]) { 30 | visited[i] = true; 31 | resMap[s][i] = 1; 32 | q.add(i); 33 | } 34 | // if(map[ver][i] == 1 ) { 35 | // resMap[s][i] = 1; 36 | // } 37 | 38 | } 39 | 40 | }//while end 41 | } 42 | 43 | public static void main(String[] args) throws NumberFormatException, IOException { 44 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 45 | 46 | n = Integer.parseInt(br.readLine()); 47 | map = new int[n][n]; 48 | visited = new boolean[n]; 49 | resMap = new int[n][n]; 50 | 51 | for (int i = 0; i < n; i++) { 52 | String[] str = br.readLine().split(" "); 53 | for (int j = 0; j < n; j++) { 54 | map[i][j] = Integer.parseInt(str[j]); 55 | } 56 | } // for end 57 | 58 | for (int i = 0; i < n; i++) { 59 | bfs(i); 60 | Arrays.fill(visited, false); 61 | } // for end 62 | 63 | // print the map 64 | for (int[] ma : resMap) { 65 | for (int m : ma) { 66 | System.out.print(m + " "); 67 | } 68 | System.out.println(); 69 | } 70 | 71 | } 72 | } 73 | 74 | ``` 75 | 76 | -------------------------------------------------------------------------------- /source/ohhako/boj/bj_1722.md: -------------------------------------------------------------------------------- 1 | # 백준 순열 문제 2 | - 1722 순열의 순서 3 | - https://www.acmicpc.net/problem/1722 4 | 5 | ## 풀이 방법 6 | ### 문제 이해하기 7 | - 입력값: N, K , 순열 8 | - 1부터 N까지의 숫자로 오름차순 순열을 만든다고 가정했을때 9 | - 출력1: K번째의 수를 구하시오 10 | - 출력2: 주어진 순열이 몇번 째(K) 수인지 구하시오 11 | 12 | ### 문제 접근 방법 13 | - 직접 순열을 만들어 sort 된 배열에서 k번째 수를 구해야하나? 14 | - 만들어진 순열에서 주어진 순열을 비교해 인덱스를 찾아야 하나? 15 | - 출력2는 순열이 주어질때 각 자릿수마다 1부터 해당 수가 될때까지 경우의 수를 구해서 자리별로 더하면 된다. 16 | - 5 2 4 7 6 3 1이 주어질때 17 | - 첫째자리가 1,2,3,4 인 경우의 수 총합 a => 6! x 4 18 | - 두번째 자리가 1인 경우의 수 총합 b => 5! 19 | - 세번째 자리가 1,3인 경우의 수 총합 c => 4! x 2 20 | - 네번째 자리가 1,3,6인 경우의 수 총합 d => 3! x 3 21 | - 다섯번째 자리가 1,3 인 경우의 수 총합 e => 2! x2 22 | - 여섯번째 자리가 1 인 경우의 수 총합 f => 1! 23 | - 일곱번째 자리는 갑 강제로 배정받으므로 상관없음 24 | 25 | - 출력1은 해당 방식으로 푼다. 26 | - N=4, 4번째 순열을 구한다면 (1234,1243,1324,1342...) 27 | - (1) 1XXX 가 되는 경우 수는 3!이며 k(4) 보다 크다. 그래서 첫자리는 1이 된다. > K 28 | - (2) 12XX 가 되는 경우의 수는 2!이며 K(4) 보다 작다. 구하고자 하는 값은 K보다 크다. 구하고자 하는 수에 해당이 안되고 다음 수가 몇번째인지 새기 위해 SUM에 넣어준다. 2< K 29 | - (3) 13XX 가 되는 경우의 수는 2!이다. SUM+2=4는 K(4)보다 크거나 같다. 둘째자리가 2라면 최대 2등이지만 3이면 최대 4등이라는 의미니 구하고자 하는 값은 두번째 자리수가 3이 된다. >=K . 해당되는 경우의 수는 SUM에서 빼야한다. 3이 되기 전 경우의 수는 2번째까지 이다. 30 | - (4) 132X 가 되는 경우의 수는 1 이다. 순서는 3번째부터 시작하므로 3이다. 31 | - (5) 134X 가 되는 경우의 수는 1! 이다. 고로 3+1 = 4번째 이므로 내가 찾는 수 이다. 32 | 33 | 34 | ### 해결하지 못한 이유 35 | - 해당 문제를 순열(Permutation)을 직접 구하여 풀려고 했다. 36 | - 나올 수 있느 최대값을 가정하면 타임오버가 나기 떄문에 다른 방법을 강구해야 했다. 37 | 38 | ### 문제를 해결한 코드 39 | ```java 40 | ``` 41 | 42 | ### 문제를 해결한 방법 43 | 44 | --- 45 | 아래의 사이트를 참고해 작성된 글입니다. 46 | - https://www.acmicpc.net/board/view/17679 47 | - https://dundung.tistory.com/60 -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj9742(순열).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | string str; 9 | int pos; 10 | int temp_pos; 11 | vectorfactorials(12); 12 | 13 | int getFactorial(int N) { 14 | int ret = 1; 15 | for (int i = N; i >= 1; i--) ret *= i; 16 | return ret; 17 | } 18 | 19 | void solve() 20 | { 21 | for (int i = 1; i <= 11; i++) factorials[i] = getFactorial(i); 22 | 23 | while (cin >> str >> pos) 24 | { 25 | temp_pos = pos; 26 | 27 | if (pos > getFactorial(str.length())) { 28 | cout << str << " " << temp_pos << " = "; 29 | cout << "No permutation" << "\n"; 30 | } 31 | else { 32 | vectorret; 33 | vectorarr; 34 | vectorvisited; 35 | int len = str.length(); 36 | 37 | for (int i = 0; i < len; i++) { 38 | arr.push_back(str[i]); 39 | visited.push_back(false); 40 | } 41 | 42 | for (int i = 1; i <= len; i++) 43 | { 44 | int cnt = 1; 45 | 46 | while (factorials[len - i] && cnt * factorials[len - i] < pos) cnt++; 47 | 48 | for (int j = 0, k = 0; j < arr.size(); j++) { 49 | if (visited[j]) continue; 50 | 51 | if (++k == cnt) { 52 | ret.push_back(str[j]); 53 | visited[j] = true; 54 | break; 55 | } 56 | } 57 | pos -= ((cnt - 1) * factorials[len - i]); 58 | } 59 | cout << str << " " << temp_pos << " = "; 60 | for (int i = 0; i < ret.size(); i++) cout << ret[i]; 61 | cout << "\n"; 62 | } 63 | } 64 | } 65 | 66 | int main() 67 | { 68 | ios_base::sync_with_stdio(0); 69 | cout.tie(0); 70 | cin.tie(0); 71 | solve(); 72 | return 0; 73 | } -------------------------------------------------------------------------------- /source/lee/team/200402_NumberPrinting.md: -------------------------------------------------------------------------------- 1 | # NumberPrinting 2 | LINE 2019 기출 3 | 4 | ## 문제 접근 방법 5 | - `크기, 숫자열`입력을 저장하는 클래스를 만듦 6 | - 최대 높이:max, 각 높이:height, 중간값:middle=max-1 7 | - TOP정렬일때 숫자가 쓰이기 시작하는 start 위치:0 8 | - MIDDLE정렬일때 숫자가 쓰이기 시작하는 start 위치:middle-h/2 9 | - BOTTOM정렬일때 숫자가 쓰이기 시작하는 start 위치:max-h+1 10 | - 각 가로줄마다 숫자의 startIdx를 비교. 만약 가로줄>=startIdx라면 그 줄에서 size만큼 숫자 프린팅 11 | 12 | ### 코드 13 | ```java 14 | import java.io.BufferedReader; 15 | import java.io.InputStreamReader; 16 | import java.util.LinkedList; 17 | import java.util.List; 18 | 19 | public class Solution { 20 | static class Number { 21 | int size; 22 | String numbers; 23 | 24 | public Number(int size, String numbers) { 25 | this.size = size; 26 | this.numbers = numbers; 27 | } 28 | 29 | } 30 | 31 | private static void printNumbers(List list, String sort) { 32 | } 33 | 34 | public static void main(String[] args) throws Exception { 35 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 36 | String[] input1 = br.readLine().split(" "); 37 | int N = Integer.parseInt(input1[0]); 38 | String sort = input1[1]; 39 | 40 | List list = new LinkedList<>(); 41 | for (int i = 0; i < N; i++) { 42 | String[] input2 = br.readLine().split(" "); 43 | Number number = new Number(Integer.parseInt(input2[0]), input2[1]); 44 | list.add(number); 45 | } 46 | 47 | printNumbers(list, sort); 48 | } 49 | } 50 | 51 | ``` 52 | 53 | ### Time complexity 54 | O() 55 | 56 | ### Space complexity 57 | O() 58 | -------------------------------------------------------------------------------- /contents/greedy.md: -------------------------------------------------------------------------------- 1 | # 탐욕법(Greedy) 알고리즘 요약설명 2 | 3 | - **분할정복 기법** 이라고도 부른다. 4 | - 문제를 작은 단위로 쪼개 반복적으로 진행하며 접근하는 방식이다. 5 | - 탐욕법은 각 단계마다 현재에 충실한 선택을 한다. 6 | - 미래의 선택, 최종 결과는 고려하지 않는다. 7 | - 반드시 최적의 해를 보장하는건 아니므로 '근사치 추정'을 위해 사용한다. 8 | 9 | 10 | ### 탐욕법을 적용한 문제 풀이 11 | - 회의실 예약을 예시로 설명. 회의 시작 시간/끝나는 시간을 갖는 회의 목록이 존재한다. 회의실 하나를 겹치치 않게 최다로 사용할때 몇개의 회의를 진행 할 수 있을까? 12 | 13 | - 탐욕적 선택 속성: 앞의 선택이 이후 선택에 영향을 주지 않는다. 답의 모든 부분을 고려하지 않고 탐욕적 선택만 하더라도 최적의 해를 구할 수 있는 속성 14 | - 최적 부분 구조: 작은 부분 문제에서 구한 최적의 답으로 합쳐진 큰 문제의 최적의 답을 구할 수 있어야 한다. 15 | 16 | 1. 문제의 답을 내는 과정을 여러 부분으로 나누자 17 | - 해: 겹치지 않고 선택한 회의 목록 18 | - 최적해: 겹치지 않고 최다로 선택한 회의 목록 19 | 2. 어떤 우선순위로 탐욕적 선택을 할지 선택 속성 결정 20 | - 회의 시간이 가장 짧은 회의부터 선택/ 가장 먼저 끝나는 회의부터 선택 21 | 3. 선택 속성이 최적 부분 구조를 만족하는지 따져본다. 22 | - 가장 빨리 끝나는 회의를 선택하면 가장 많은 회의를 선택 할 수 있다. 23 | 24 | 25 | 26 | ### 알고리즘 개선 방향 27 | 28 | 문제를 작은 단위로 쪼개 풀다보면 같은 문제를 반복해 푸는 경우가 있는데 이 때 그 문제들을 매번 재계산 하지 않고 값을 저장해두었다가 재사용 하는 동적프로그래밍(DP) 기법을 이용 할 수 있다. 29 | - [DP 요약설명](https://github.com/TheCopiens/algorithm-study/blob/master/contents/DP.md) 30 | 31 | ### 탐욕법을 활용한 문제 32 | * 동전을 최소 개수로 거슬러주기 33 | * [체육복](https://github.com/TheCopiens/algorithm-study/blob/ohhako/source/ohhako/200202_greedy.md) 34 | * [큰수만들기](https://programmers.co.kr/learn/courses/30/lessons/42883) 35 | * [RGB거리](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/boj/1149_dp.md) 36 | * [정수 삼각형](https://github.com/TheCopiens/algorithm-study/blob/master/source/ohhako/boj/1932_DP.md) 37 | * [동물원](https://www.acmicpc.net/problem/1309) 38 | * [기타리스트](https://www.acmicpc.net/problem/1495) 39 | * [LCS](https://www.acmicpc.net/problem/9251) 40 | * [동전2](https://www.acmicpc.net/problem/2294) 41 | -------------------------------------------------------------------------------- /source/soyeon/[programmers] 43163.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 문제 2 | 3 | - 단어 변환 4 | - https://programmers.co.kr/learn/courses/30/lessons/43163 5 | 6 | ### 문제 이해하기 7 | 두 개의 단어 begin, target과 단어의 집합 words가 매개변수로 주어질 때, 최소 몇 단계의 과정을 거쳐 begin을 target으로 변환할 수 있는지 찾는 문제 8 | 9 | ### 문제 접근 방법 10 | index에 해당하는 char을 바꿔주면서 단어 변환을 모든 경우의 수를 한 담에 최소 경우를 찾는다. 11 | 12 | ### 구현 배경 지식 13 | dfs 14 | 15 | ### 접근 방법을 적용한 코드 16 | ```java 17 | class Solution { 18 | public boolean isDiffOneChar(String str1, String str2) { 19 | int cnt = 0; 20 | for (int i = 0; i < str1.length() && cnt < 2; i++) { 21 | if (str1.charAt(i) != str2.charAt(i)) { 22 | cnt++; 23 | } 24 | } 25 | return cnt == 1; 26 | } 27 | 28 | public int dfs(String begin, String target, int index, String[] words, boolean[] visited, int cnt) { 29 | if (begin.equals(target)) { 30 | return cnt; 31 | } 32 | if (visited[index]) { 33 | return cnt; 34 | } 35 | visited[index] = true; 36 | int ans = 0; 37 | for (int i = 0; i < words.length; i++) { 38 | if (index != i && isDiffOneChar(begin, words[i]) && !visited[i]) { 39 | ans = dfs(words[i], target, i, words, visited, cnt + 1); 40 | } 41 | } 42 | return ans; 43 | } 44 | 45 | public int solution(String begin, String target, String[] words) { 46 | int answer = words.length + 1; 47 | for (int i = 0; i < words.length; i++) { 48 | boolean[] visited = new boolean[words.length]; 49 | if (isDiffOneChar(begin, words[i])) { 50 | answer = Math.min(answer, dfs(words[i], target, i, words, visited, 1)); 51 | } 52 | } 53 | if (answer == words.length + 1) { 54 | return 0; 55 | } 56 | return answer; 57 | } 58 | 59 | } 60 | ``` 61 | -------------------------------------------------------------------------------- /docs/java/priorityQueue.md: -------------------------------------------------------------------------------- 1 | ## 우선순위 큐(Priority Queue) 요약 정리 2 | - BIFO(Best-in,First out)형 자료구조 3 | - 우선순위가 가장 높은 데이터가 먼저 나온다. 4 | - 데이터에 근거해 우선순위를 판단한다. 5 | - 어떤 데이터를 기준으로 우선순위를 부여할지 프로그래머의 판단이 필요하다. 6 | - 우선순위가 같을수도 있다. 7 | - 자바에서 Priority queue API를 지원한다. 8 | 9 | ### 선언 및 기본 연산 10 | - PriorityQueue q = new PriorityQueue<>(); 11 | - q.offer() 12 | - q.poll() 13 | - q.toString(): 요소 모두 출력 14 | - PriorityQueue 객체 선언시 제네릭 타입을 지정해야 한다. 15 | - 클래스 지정시엔 해당 클래스에 Comparable 인터페이스를 보수하여 compareTo메서드를 오버라이드 해야한다. compareTo 메서드에서 우선순위 지정이 가능하다. 16 | - 객체를 비교해야 하므로 compareTo 메서드는 반드시 **객체의 클래스 내부**에 작성한다. 17 | 18 | ### 예시 코드 1 19 | ```java 20 | package priorityQueue; 21 | public class Graduate implements Comparable{ 22 | String name; 23 | int grade; 24 | public Graduate(String name,int grade) { 25 | this.name= name; 26 | this.grade = grade; 27 | } 28 | 29 | @Override 30 | public int compareTo(Graduate gr) { 31 | if(this.grade < gr.grade) 32 | return 1; 33 | else if(this.grade > gr.grade) 34 | return -1; 35 | return 0; 36 | } 37 | } 38 | ``` 39 | 40 | ```java 41 | package priorityQueue; 42 | import java.util.*; 43 | 44 | public class Main { 45 | public static void main(String[] args) { 46 | PriorityQueue graduates = new PriorityQueue(); 47 | graduates.offer(new Graduate("harry",6)); 48 | graduates.offer(new Graduate("ron",6)); 49 | graduates.offer(new Graduate("chalie",7)); 50 | graduates.offer(new Graduate("genie",5)); 51 | graduates.offer(new Graduate("kozi",2)); 52 | 53 | int len = graduates.size(); 54 | for(int i=0 ; i= 25 30 | || height <= 0 || height >= 25 31 | || x < 0 || x >= 25 32 | || y < 0 || y >= 25; 33 | } 34 | 35 | public static void main(String[] args) throws Exception { 36 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 37 | String[] rowCol = br.readLine().split(" "); 38 | String[] conyCoordinate = br.readLine().split(" "); 39 | 40 | int width = Integer.parseInt(rowCol[0]); 41 | int height = Integer.parseInt(rowCol[1]); 42 | int x = Integer.parseInt(conyCoordinate[0]); 43 | int y = Integer.parseInt(conyCoordinate[1]); 44 | 45 | playTag(width, height, x, y); 46 | } 47 | } 48 | ``` 49 | 50 | ### Time complexity 51 | O(x\*y) 52 | 53 | ### Space complexity 54 | O(x\*y) 55 | -------------------------------------------------------------------------------- /source/lee/200317_dp.md: -------------------------------------------------------------------------------- 1 | # 등굣길 2 | https://programmers.co.kr/learn/courses/30/lessons/42898 3 | 4 | ## 문제 접근 방법 5 | (m,n-1) 6 |  ↓ 7 | (m-1,n) → (m,n) 8 | 9 | 1. puddles를 오름차순으로 정렬 10 | 2. arr[1][1]=1로 초기화해두고, 그 다음부턴 (m-1,n)+(m,n-1)로 가짓수를 더해나감 11 | 3. puddles가 있는 곳이라면 계산하지않고 0으로 두고 넘어감 12 | 13 | ### 문제점 14 | - 문제에서 주어진 m,n과 코드에서 계산한 x,y의 순서가 반대여서 헷갈렸다 15 | - modulo연산을 중간에서 해주지 않으면 중간 연산을 하다가 int범위를 초과할 수 있어 오류가 발생한다. 16 | 17 | 18 | ### 해결한 코드 19 | ```java 20 | import java.util.Arrays; 21 | import java.util.Comparator; 22 | 23 | class Solution { 24 | public int solution(int m, int n, int[][] puddles) { 25 | Arrays.sort(puddles, new Comparator() { 26 | @Override 27 | public int compare(int[] o1, int[] o2) { 28 | if (o1[1] == o2[1]) return o1[0] - o2[0]; 29 | return o1[1] - o2[1]; 30 | } 31 | }); 32 | 33 | int[][] arr = new int[n + 1][m + 1]; 34 | arr[1][1] = 1; 35 | 36 | int puddleIdx = 0; 37 | for (int x = 1; x <= n; x++) { 38 | for (int y = 1; y <= m; y++) { 39 | if (x==1&&y==1) continue; 40 | if (puddleIdx < puddles.length && 41 | y == puddles[puddleIdx][0] && x == puddles[puddleIdx][1]) { 42 | arr[x][y] = 0; 43 | puddleIdx++; 44 | continue; 45 | } 46 | arr[x][y] = (arr[x - 1][y] + arr[x][y - 1])% 1000000007; 47 | } 48 | } 49 | return arr[n][m]; 50 | } 51 | } 52 | ``` 53 | ### Time complexity 54 | T(puddles sort) + O(m\*n) 55 | 56 | ### Space complexity 57 | O(m\*n) 58 | -------------------------------------------------------------------------------- /docs/java/heap.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | public class Main { 5 | public static class MinHeap{ 6 | private List heap; 7 | 8 | public MinHeap() { 9 | this.heap = new ArrayList<>(); 10 | heap.add(0); //인덱스1부터 사용하기 위해 11 | } 12 | //요소 삽입 13 | public void insert(int val) { 14 | heap.add(val); //일단넣고 15 | int p = heap.size() -1; //마지막 요소의 인덱스. 즉 바로 위에 담은 요소의 인덱스. 즉 p=신입 16 | 17 | while(p>1 && (heap.get(p/2)>heap.get(p))){ //반복하는 조건 : p보다 p의 부모가 값 더 크다, p는 1보다 크다 18 | int tmp = heap.get(p/2); 19 | heap.set(p/2,heap.get(p)); 20 | heap.set(p,tmp); 21 | p=p/2; //신입이 부모위치로 올라간다! 22 | } 23 | } 24 | //노드 삭제. (루트 노드부터) 25 | public int delete() { 26 | if(heap.size()<=1) return 0; 27 | int deleteValue = heap.get(1); 28 | 29 | heap.set(1,heap.get(heap.size()-1)); 30 | heap.remove(heap.size()-1); 31 | 32 | int pos=1; 33 | while(pos*2 < heap.size()) { 34 | int minPos = pos*2; //자식 위치 35 | int minValue = heap.get(pos*2); //자식 값 36 | if((minPos+1) daysToFinish = new LinkedList<>(); 35 | for(int i = 0; i < progresses.length; i++) { 36 | daysToFinish.add(computeDays(progresses[i], speeds[i])); 37 | } 38 | 39 | int progressToFinish = daysToFinish.poll(); 40 | int count = 1; 41 | 42 | ArrayList list = new ArrayList<>(); 43 | 44 | while(!daysToFinish.isEmpty()) { 45 | if(progressToFinish >= daysToFinish.peek()) { 46 | daysToFinish.poll(); 47 | count++; 48 | }else { 49 | list.add(count); 50 | count = 1; 51 | progressToFinish = daysToFinish.poll(); 52 | } 53 | } 54 | list.add(count); 55 | 56 | return list.stream().mapToInt(Integer::intValue).toArray(); 57 | } 58 | } 59 | ``` 60 | -------------------------------------------------------------------------------- /source/JmKanmo/PS(Korean)/boj9935(문자열폭발-스택).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | string str; 12 | string target; 13 | maphash_map; 14 | 15 | void init() 16 | { 17 | cin >> str; 18 | cin >> target; 19 | for (int i = 1; i <= target.length(); i++) { 20 | hash_map[target.substr(i - 1, 1)] = i; 21 | } 22 | } 23 | 24 | void solve() 25 | { 26 | stackst; 27 | 28 | for (int i = 0; i < str.length(); i++) 29 | { 30 | st.push(str.substr(i, 1)); 31 | 32 | if (hash_map[str.substr(i, 1)] == target.length()) 33 | { 34 | if (st.size() < target.size()) continue; 35 | 36 | stacktemp_st; 37 | bool flag = true; 38 | 39 | for (int j = 0; j < target.length(); j++) 40 | { 41 | string prev_str = st.top(); 42 | temp_st.push(prev_str); 43 | st.pop(); 44 | 45 | if (hash_map[prev_str] != target.length() - j) { 46 | flag = false; 47 | break; 48 | } 49 | } 50 | 51 | if (!flag) 52 | { 53 | while (temp_st.empty() != true) { 54 | st.push(temp_st.top()); 55 | temp_st.pop(); 56 | } 57 | } 58 | else { 59 | while (temp_st.empty() != true) 60 | temp_st.pop(); 61 | } 62 | } 63 | } 64 | 65 | if (st.empty()) { 66 | cout << "FRULA" << endl; 67 | } 68 | else { 69 | string answer = ""; 70 | while (st.empty() != true) { 71 | answer += st.top(); 72 | st.pop(); 73 | } 74 | reverse(answer.begin(), answer.end()); 75 | cout << answer << endl; 76 | } 77 | } 78 | 79 | int main() 80 | { 81 | ios_base::sync_with_stdio(0); 82 | cout.tie(0); 83 | cin.tie(0); 84 | 85 | init(); 86 | solve(); 87 | return 0; 88 | } -------------------------------------------------------------------------------- /source/lee/200305_sort.md: -------------------------------------------------------------------------------- 1 | # 가장 큰 수 2 | - https://programmers.co.kr/learn/courses/30/lessons/42746 3 | 4 | ## 문제 접근 방법 5 | 1. int array -> String array로 변환 6 | 2. 내림차순 정렬 7 | -> 이 경우 {10, 100, 1000}이 100010010이 나와서 오답 8 | 도저히 접근 방법이 생각나지 않아서 다른 사람의 풀이를 보았다. 9 | *핵심은 string 상태의 A+B 와 B+A 를 비교하여 내림차순으로 정렬* 10 | 이라는 설명을 보고 바로 풀 수 있었다. 11 | 12 | 13 | ### 해결한 코드 14 | ```java 15 | import java.util.*; 16 | import java.util.stream.Collectors; 17 | 18 | class Solution { 19 | public String solution(int[] numbers) { 20 | Comparator biggestNumber = (n1, n2) -> (n2.concat(n1)).compareTo(n1.concat(n2)); 21 | String answer = Arrays.stream(numbers) 22 | .mapToObj(number -> Integer.toString(number)) 23 | .sorted(biggestNumber) 24 | .collect(Collectors.joining()); 25 | if (answer.startsWith("0")) return "0"; 26 | return answer; 27 | } 28 | } 29 | ``` 30 | ### Time complexity 31 | T(n)+T(sort)+T(collect), n=numbers.length 32 | T(n): mapToObj에서 numbers의 모든 원소를 String으로 변환 33 | 34 | ### Space complexity 35 | O(n) n=numbers.length 36 | stream은 딱히 저장공간이 있는 것이 아니라서 그 stream의 source만 생각하면 됨 37 | 참고: https://stackoverflow.com/questions/29787684/java-8-stream-vs-collection-storage 38 | 39 | 40 | ## 추가로 공부할 것 41 | 1. Arrays.stream()과 Stream.of() 차이점 정리 42 | stream을 쓰는 방법이 Arrays.stream()과 Stream.of()가 있었다. Arrays.stream()을 쓸 경우 sorted에 내가 커스텀한 Comparator 사용이 안 됐다(컴파일러 에러). int array를 정렬하는 방법은 오름차순 아니면 내림차순밖에 없으니까 커스텀한 Comparator를 사용하는것이 어불성설이라 안되었던것같다. 43 | 44 | - Arrays.stream(): array로 스트림을 만들때 45 | - Stream.of(): collection의 스트림을 만들때 46 | 47 | 2. Collectors.joining() 정리 48 | 문자열 스트림의 모든 요소를 하나의 문자열로 연결해서 반환. 구분자를 지정해줄 수도 있고, 접두사와 접미사도 지정 가능. 쓰트림의 요소가 String이나 StringBuffer처럼 CharSequence의 자손인 경우에만 결합 가능. 49 | 출처: Java의 정석 50 | -------------------------------------------------------------------------------- /source/diane/[baekjoon]2839.md: -------------------------------------------------------------------------------- 1 | # Baekjoon 설탕 배달 문제 2 | 3 | - 설탕 배달 4 | - https://www.acmicpc.net/problem/2839 5 | 6 | ### 문제 이해하기 7 | 설탕을 정확히 N킬로그램 배달해야 한다. 8 | 사용할 수 있는 봉지는 두 가지로, 3킬로그램 봉지와 5킬로그램 봉지가 있다. 9 | 필요한 봉지의 수를 가장 적게 사용하면서, 설탕을 배달할 때, 사용하는 봉지의 수를 구하여라. 10 | 만약 이 봉지로 정확히 N킬로그램을 만들 수 없다면 -1을 반환한다. 11 | 12 | #### 입력 13 | - int N : 배달하는 설탕의 무게 (킬로그램) 14 | - 3 이상 5000 이하 15 | 16 | #### 출력 17 | - int : 필요한 최소의 설탕 봉지 수 18 | 19 | ### 문제 접근 방법 20 | N킬로그램의 설탕을 담는 최소 설탕 봉지를 S(N)이라고 하자. 21 | S(N) = min(not -1)(S(N-3), S(N-5))+1 22 | = -1 (S(n-3)=S(N-5)=-1인 경우) 23 | 24 | ### 구현 배경 지식 25 | Dynamic Programming (Memoization) 26 | 27 | ### 문제를 해결한 코드 28 | ~~~java 29 | import java.util.HashMap; 30 | import java.util.Scanner; 31 | 32 | public class Main { 33 | public static HashMap cups; 34 | 35 | public static void main(String args[]) { 36 | Scanner sc = new Scanner(System.in); 37 | int sugar = sc.nextInt(); 38 | 39 | cups = new HashMap<>(); 40 | cups.put(3,1); 41 | cups.put(5,1); 42 | cups.put(1,-1); 43 | cups.put(2,-1); 44 | cups.put(4,-1); 45 | cups.put(6,2); 46 | 47 | System.out.println(calculate(sugar)); 48 | } 49 | 50 | private static int calculate(int sugar) { 51 | if (cups.containsKey(sugar)) return cups.get(sugar); 52 | 53 | int cup = -1; 54 | int cup1 = calculate(sugar-5); 55 | int cup2 = calculate(sugar-3); 56 | 57 | if (cup1 != -1) { 58 | if (cup2 != -1) { 59 | cup = (cup1 > cup2? cup2:cup1)+1; 60 | } else { 61 | cup = cup1+1; 62 | } 63 | } else if (cup2 != -1) { 64 | cup = cup2+1; 65 | } 66 | 67 | cups.put(sugar, cup); 68 | 69 | return cup; 70 | } 71 | } 72 | ~~~ -------------------------------------------------------------------------------- /source/lee/team/20200419_카카오.md: -------------------------------------------------------------------------------- 1 | # 카카오 2 | 3 | 4 | ## 문제 접근 방법 5 | 6 | ### 코드 7 | ```java 8 | class Solution { 9 | public static boolean solution(int[][] key, int[][] lock) { 10 | int[][] key90 = turn90degree(key); 11 | int[][] key180 = turn90degree(key90); 12 | int[][] key270 = turn90degree(key180); 13 | 14 | int m=key.length; 15 | int n=lock.length; 16 | int len=n+2*m-2; 17 | int[][] bigArr = new int[len][len]; 18 | for (int i=0;i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | int answer = 0; 13 | int banner_cnt = 0; 14 | int userId_cnt = 0; 15 | vectorids; 16 | vectoruserId; 17 | vectorbannerId; 18 | int visited[9]; 19 | bool flag = false; 20 | 21 | bool check(string user, string banner) { 22 | if (user.length() != banner.length()) 23 | return false; 24 | else { 25 | for (int i = 0; i < user.length(); i++) { 26 | if (banner[i] == '*' || user[i] == banner[i]) 27 | continue; 28 | else { 29 | return false; 30 | } 31 | } 32 | return true; 33 | } 34 | } 35 | 36 | void checkId(int idx) 37 | { 38 | if (idx >= ids.size()) { 39 | flag = true; 40 | return; 41 | } 42 | 43 | for (int i = 0; i < bannerId.size(); i++) { 44 | if (!visited[i] && check(userId[ids[idx]], bannerId[i])) { 45 | visited[i] = 1; 46 | checkId(idx + 1); 47 | visited[i] = 0; 48 | } 49 | } 50 | } 51 | 52 | void dfs(int idx, int cnt) 53 | { 54 | if (cnt >= banner_cnt) 55 | { 56 | checkId(0); 57 | if (flag) { 58 | answer++; 59 | flag = false; 60 | } 61 | return; 62 | } 63 | 64 | for (int i = idx + 1; i < userId_cnt; i++) { 65 | ids.push_back(i); 66 | dfs(i, cnt + 1); 67 | ids.pop_back(); 68 | } 69 | } 70 | 71 | int solution(vector user_id, vector banned_id) { 72 | userId = user_id; 73 | bannerId = banned_id; 74 | banner_cnt = banned_id.size(); 75 | userId_cnt = user_id.size(); 76 | dfs(-1, 0); 77 | return answer; 78 | } 79 | 80 | int main() 81 | { 82 | ios_base::sync_with_stdio(0); 83 | cout.tie(0); 84 | cin.tie(0); 85 | cout << solution({ "frodo", "fradi", "crodo", "abc123", "frodoc" }, { "fr*d*", "*rodo", "******", "******" }) << endl; 86 | return 0; 87 | } -------------------------------------------------------------------------------- /source/ohhako/boj/bj_1010.md: -------------------------------------------------------------------------------- 1 | # 백준 dp 문제 2 | 3 | - 다리 놓기 4 | - https://www.acmicpc.net/problem/1010 5 | 6 | ## 풀이 방법 7 | 8 | ### 문제 이해하기 9 | 10 | - 입력값: 테스트케이스 (t), t개의 n, m 11 | - 출력값: 좌에 사이트 n개, 우측에 n개보다 적은 사이트 m개가 존재할때 다리가 겹치지 않게 최대로 사이트를 이어놓을 수 있는 경우의 수 12 | 13 | ### 문제 접근 방법 14 | 15 | - DP문제를 접근할때 하나의 규칙을 두어 반복수행, 예외를 고려해야 한다. 16 | - n개의 다리를 놓을 수 있는 경우는 최소 17 | 18 | ### 해결하지 못한 이유 19 | 20 | - 조합(Combination)공식 계산하는 방법을 잊었다. 21 | - long보다 더 큰 자료인 BigInteger를 떠오르지 못했다. 22 | 23 | ### 문제를 해결한 코드 24 | 25 | ```java 26 | import java.io.IOException; 27 | import java.io.InputStreamReader; 28 | import java.io.BufferedReader; 29 | import java.math.BigInteger; 30 | 31 | public class Main { 32 | public static void makeBridge(int n, int m) { 33 | BigInteger parent = BigInteger.ONE; 34 | BigInteger child = BigInteger.ONE; 35 | 36 | for (int i = 1; i <= n ; i++) { 37 | parent = parent.multiply(BigInteger.valueOf(m-i+1)); 38 | child = child.multiply(BigInteger.valueOf(i)); 39 | } 40 | System.out.println(parent.divide(child)); 41 | } 42 | 43 | public static void main(String[] args) throws IOException { 44 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 45 | int t = Integer.parseInt(br.readLine()); 46 | for (int i = 0; i < t; i++) { 47 | String[] cmd = br.readLine().split(" "); 48 | makeBridge(Integer.parseInt(cmd[0]), Integer.parseInt(cmd[1])); 49 | } 50 | } 51 | } 52 | ``` 53 | 54 | ### 문제를 해결한 방법 55 | 56 | - [조합](https://github.com/TheCopiens/algorithm-study/blob/master/contents/%EA%B2%BD%EC%9A%B0%EC%9D%98%EC%88%98.md)을 이해한 후 공식을 이용하여 풀이를 설계했다. 57 | - n과 m이 둘다 30일 경우 30의 30제곱을 계산해야 하는데 이는 long이 감당 할 수 있는 범위를 넘어서는 값이기 때문에 `import java.math.BigInteger`를 선언하여 BigInteger 자료구조를 이용해야 했다. 58 | - BigInteger는 값 초기화, 곱셈,나눗셈 연산을 수행하는 함수를 호출해야 한다. 59 | - 함수 호출시 인자로 넘어가는 int형 값 또한 BigInteger이어야 하므로 valueOf 메서드로 변환해주었다. 60 | 61 | --- 62 | 63 | 아래의 사이트를 참고해 작성된 글입니다. 64 | -------------------------------------------------------------------------------- /source/ohhako/coding test/200226_queue.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 스택/큐 문제 2 | - 기능개발 3 | - https://programmers.co.kr/learn/courses/30/lessons/42586 4 | ## 풀이 방법 5 | ### 문제와 주어진 조건 이해하기 6 | - 입력 데이터 progresses 배열의 순서대로 작업을 배포한다. 7 | - 앞의 작업이 끝나야 뒤 작업이 배포가 가능하다. 8 | - 작업은 동시에 시작되지만 처리 속도는 각각이다. 9 | - 배포시에 몇개의 작업을 동반하는지 배열로 출력하라. 10 | 11 | 12 | ### 문제 접근 방법 13 | - 입력 데이터인 두개의 배열을 이용해 각 작업마다 며칠에 처리가 가능한지 계산해 큐에 저장했다. 14 | - 배열 또는 큐 사용가능 15 | - 전 값에 의해 현재 값이 저장되냐 마느냐의 영향을 받으므로 순회 전에 가장 처음의 데이터를 꺼내 저장했다. 16 | - 풀이 순서 17 | 1. 며칠에 처리 가능한지 계산해 큐에 저장 18 | 2. 가장 처음 값을 꺼내 max로 저장 19 | 3. 큐에 요소가 텅빌때까지 순회 20 | - 현재값이 max보다 작으면 count 21 | - 현재값이 max보다 크면 이전에 쌓인 count를 리스트에 저장, count=1 , 현재값이 max가 됨 22 | 23 | ### 구현 배경 지식 24 | - double형 변수에 int형 데이터들을 연산시킨 결과를 소수점으로 낼 수 있다. 25 | - (double형 변수 초기화시 소수점 필요없음, int데이들 연산시킬때 (double) 캐스팅 필요없음) 26 | 27 | 28 | ### 접근 방법을 적용한 코드 29 | ```java 30 | import java.util.*; 31 | class Solution { 32 | public int[] solution(int[] progresses, int[] speeds) { 33 | double day = 0; 34 | Queue q = new LinkedList<>(); 35 | 36 | for(int i=0 ; i list = new ArrayList<>(); 45 | while(!q.isEmpty()){ 46 | int e = q.poll(); 47 | if(e<=max) 48 | count++; 49 | if(e>max){ 50 | list.add(count); 51 | count=1; 52 | max = e; 53 | } 54 | } 55 | list.add(count); 56 | int[] answer = new int[list.size()]; 57 | for(int i=0 ; i 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | typedef pair Pair; 12 | 13 | const int idx_1[] = { 0,0,1,-1 }; 14 | const int idx_2[] = { 1,-1,0,0 }; 15 | 16 | int N; 17 | int board[26][26]; 18 | int visited[26][26]; 19 | vectoranswer; 20 | 21 | void init() 22 | { 23 | cin >> N; 24 | 25 | for (int i = 1; i <= N; i++) 26 | { 27 | string str; 28 | cin >> str; 29 | 30 | for (int j = 1; j <= N; j++) { 31 | board[i][j] = str[j - 1] - '0'; 32 | } 33 | } 34 | } 35 | 36 | int bfs(Pair start) 37 | { 38 | queueq; 39 | int cnt = 0; 40 | 41 | q.push(start); 42 | visited[start.first][start.second] = 1; 43 | 44 | while (q.empty() != true) 45 | { 46 | Pair pos = q.front(); 47 | q.pop(); 48 | cnt++; 49 | 50 | for (int i = 0; i < 4; i++) 51 | { 52 | Pair next = Pair(pos.first + idx_1[i], pos.second + idx_2[i]); 53 | 54 | if (next.first<1 || next.first>N || next.second<1 || next.second>N) 55 | continue; 56 | 57 | if (board[next.first][next.second] && visited[next.first][next.second] == 0) 58 | { 59 | q.push(next); 60 | visited[next.first][next.second] = 1; 61 | } 62 | } 63 | } 64 | return cnt; 65 | } 66 | 67 | int solve() 68 | { 69 | int cnt = 0; 70 | 71 | for (int i = 1; i <= N; i++) 72 | { 73 | for (int j = 1; j <= N; j++) 74 | { 75 | if (board[i][j] && visited[i][j] == 0) 76 | { 77 | cnt++; 78 | int k = bfs(Pair(i, j)); 79 | if (k > 0) answer.push_back(k); 80 | } 81 | } 82 | } 83 | sort(answer.begin(), answer.end()); 84 | return cnt; 85 | } 86 | 87 | int main() 88 | { 89 | ios_base::sync_with_stdio(false); 90 | cout.tie(0); 91 | cin.tie(0); 92 | 93 | init(); 94 | cout << solve() << endl; 95 | for (int elem : answer) { 96 | cout << elem << endl; 97 | } 98 | return 0; 99 | } -------------------------------------------------------------------------------- /source/ohhako/200208_number.md: -------------------------------------------------------------------------------- 1 | # 프로그래머스 연습문제 2 | - 약수의 합 3 | - https://programmers.co.kr/learn/courses/30/lessons/12928 4 | 5 | ## 약수의 합 6 | ### 문제 접근 방법 7 | - n의 약수 찾아 자료구조에 저장 8 | - 저장한 값을 모두 더하기 9 | - 저장할 데이터의 수가 가변적이므로 동적데이터 자료 이용 10 | 11 | ### 배경지식 12 | - ArrayList 사용하는 방법 13 | - 약수를 찾을때 최소의 순회만 하는 방법 14 | 15 | ### 비슷한 문제 16 | - [소수찾기](https://programmers.co.kr/learn/courses/30/lessons/12921) 17 | 18 | ### 접근 방법을 적용한 코드 19 | ```java 20 | import java.util.*; 21 | class Solution { 22 | public int solution(int n) { 23 | int answer = 0; 24 | List total = new ArrayList<>(); 25 | for(int i=1 ; i<=n ; i++){ 26 | if(n%i==0) 27 | total.add(i); 28 | } 29 | for(int i=0 ; i total = new ArrayList<>(); 53 | for(int i=1 ; i*i<= n ; i++){ 54 | if(n%i==0){ //약수인데 55 | total.add(i); 56 | if(i*i!=n){ // 제곱이 아니라면 57 | total.add(n/i); 58 | } 59 | } 60 | 61 | } 62 | for(int i=0 ; i