![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FAlKjS%2FbtqKxRxB3Da%2FiWMcvF9DHd9PIjEz99NGp1%2Fimg.png)
[알고리즘 문제] 61. 특정 수 만들기(DFS : MS 인터뷰)
2020. 10. 9. 18:04
문제 풀이/알고리즘 문제풀이
코드 #include #include #include #include using namespace std; vector nums; int m; int cnt = 0; void DFS(int L, int value) { if (L == nums.size()) { if (m == value) { ++cnt; } } else { DFS(L + 1, value + nums[L]); DFS(L + 1, value - nums[L]); DFS(L + 1, value); } } int main(void) { int n, i; cin >> n >> m; nums.resize(n); for (i = 0; i > nums[i]; } DFS(0, 0); cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FNoWJd%2FbtqKuGCtydj%2FdDt4mLCK8kYxukwXkXL4r0%2Fimg.png)
[알고리즘 문제] 60. 합이 같은 부분집합(DFS : 아마존 인터뷰)
2020. 10. 8. 10:23
문제 풀이/알고리즘 문제풀이
코드 #include #include #include #include using namespace std; int n, ch[11], arr[11]; vector v; bool isEnd = false; void DFS(int L) { if (isEnd) return; int i, sum = 0; if (L == n + 1) { for (i = 1; i arr[i]; } DFS(1); if(!isEnd) cout arr[i]; } DFS(1); cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbwg5WM%2FbtqKqzklvmU%2FY388lmuxCZRvjmuA8KXUF1%2Fimg.png)
[알고리즘 문제] 59. 부분집합(DFS)
2020. 10. 8. 09:53
문제 풀이/알고리즘 문제풀이
코드 #include #include using namespace std; int n, ch[11]; void DFS(int L) { int i; if (L == n + 1) { for (i = 1; i
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FdwQalb%2FbtqKmoP5lOx%2FPgkmJKE4FpPQmVhZ04kyj1%2Fimg.png)
[알고리즘 문제] 58. 이진트리 깊이우선탐색(DFS)
2020. 10. 7. 10:32
문제 풀이/알고리즘 문제풀이
코드 #include #include #include #include using namespace std; void D(int v) { if (v > 7) return; else { cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2F3qoFF%2FbtqKjc3XWgT%2F1kK4BwsaG5b77bGUcLwsUk%2Fimg.png)
[알고리즘 문제] 57. 재귀함수 이진수 출력
2020. 10. 7. 10:16
문제 풀이/알고리즘 문제풀이
코드 #include #include #include #include using namespace std; void recur(int n) { if (n == 0) return; else { recur(n / 2); cout > n; recur(n); return 0; } 출력 결과 채점 결과 해당 포스트는 'it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비' 강의를 수강하며 개인 백업용으로 메모하였습니다. 인프런: https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98# it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비 - 인프런 알고리즘과 자료구조를 이용해 문제해결력을 기르는게..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcRJNci%2FbtqKkOItQu4%2FgrZcx2kPgGNOxqfl2HbleK%2Fimg.png)
[알고리즘 문제] 56. 재귀함수 분석
2020. 10. 7. 10:03
문제 풀이/알고리즘 문제풀이
코드 #include #include #include #include using namespace std; void recur(int n) { if (n == 0) return; else { recur(n - 1); cout n; recur(n); return 0; } 출력 결과 함수가 호출되면 stack에 스택 프레임이 생성된다. 스택 프레임은 호출 정보(지역 변수, 매개변수, 복귀해야 할 주소 등)를 기록한다. 해당 포스트는 'it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비' 강의를 수강하며 개인 백업용으로 메모하였습니다. 인프런: https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98# it 취업을 위..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbEBKPS%2FbtqKhly4m6R%2Fmcry5yKJHAeS49rCv17Nm1%2Fimg.png)
[알고리즘 문제] 55. 기차운행(stack 응용)
2020. 10. 6. 10:03
문제 풀이/알고리즘 문제풀이
코드 #include #include #include #include using namespace std; int main(void) { int n, m, i, idx = 0; cin >> n; stack st; vector vt(n); vector vt2(n); vector vtc; for (i = 0; i > vt2[i]; st.push(vt2[i]); vtc.push_back('P'); while (true) { if (st.empty()) break; if (st.top() == vt[idx]) { st.pop(); vtc.push_back('O'); ++idx; } else break; }..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FtijeU%2FbtqKib34Lbs%2FHksY5XSNbzBvdbwnEBuo81%2Fimg.png)
[알고리즘 문제] 54. 올바른 괄호(stack)
2020. 10. 6. 09:39
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int i, flag = 0; char c[31]; cin >> c; stack st; for (i = 0; c[i] != '\0'; ++i) { if (c[i] == '(') st.push(c[i]); else { if (st.empty()) { cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FGszvV%2FbtqKdFE5YJV%2FC3wodMzCa7s1TTd4LfC3O0%2Fimg.png)
[알고리즘 문제] 53. K진수 출력
2020. 10. 6. 09:29
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, k, tmp, i; cin >> n >> k; char arr[100]; int top = -1; char c[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; tmp = n; while (tmp != 0) { arr[++top] = c[tmp % k]; tmp /= k; } while (top > -1) { cout > n >> k; stack sChar; char arr[100]; int top = -1; char c[16] = { '0', '1', '2', ..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbRr58f%2FbtqKiaqpGnd%2Fvk2c1U8pP7Kwl0mKR6k7l0%2Fimg.png)
[알고리즘 문제] 52. Ugly Numbers
2020. 10. 6. 01:09
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i; cin >> n; vector vInt(n + 1); int p2 = 1, p3 = 1, p5 = 1, min = 2147000000; int v2, v3, v5; vInt[1] = 1; for (i = 2; i
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FczlPFz%2FbtqKfq8BWwd%2Fc56Gs3NvYVoQrxLHNHhYlk%2Fimg.png)
[알고리즘 문제] 51. 영지(territory) 선택 : (large)
2020. 10. 5. 23:57
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int h, w, i, j, sum, max = -2147000000; cin >> h >> w; vector a(h + 1, vector(w + 1)); vector dy(h + 1, vector(w + 1)); for (i = 1; i a[i][j]; dy[i][j] = dy[i][j-1] + dy[i-1][j] - dy[i-1][j-1] + a[i][j]; } } int hh, ww, tmp; cin >> hh >> ww; for (i = hh; i
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fczy0JL%2FbtqJ0oKLT9U%2FsM4ZNUqkXNXJxQRK1LRXAk%2Fimg.png)
[알고리즘 문제] 50. 영지(territory) 선택 : (small)
2020. 10. 4. 20:59
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int h, w, i, j, t; int height, width, max = -2147000000; int p1, p2; cin >> h >> w; vector vInt; vector temp; for (i = 0; i > temp[j]; } vInt.push_back(temp); } cin >> height >> width; for (i = 0; i = height) break; t += vInt[i + p1][j + p2]; p2++; } if (ma..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FBeW3d%2FbtqJ0nYRpfr%2FbbXXqxufZj7wTgQmz4ykXk%2Fimg.png)
[알고리즘 문제] 49. 블록의 최댓값
2020. 10. 3. 21:03
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, temp, i, j, count = 0; cin >> n; vector vInt; vector vTemp; for (i = 0; i > temp; vTemp.clear(); for (j = 0; j > temp; for (j = 0; j temp) vInt[j][i] = temp; count += vInt[j][i]; } } c..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FDEQ7f%2FbtqJ3gLHD42%2FuglUm0qvMFXsp61yMujIuK%2Fimg.png)
[알고리즘 문제] 48. 각 행의 평균과 가장 가까운 값
2020. 10. 3. 19:39
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int arr[9][10] = { 0 }; int num[9] = { 0 }; int i, j, sum = 0; float temp; for (i = 0; i > arr[i][j]; temp += arr[i][j]; } temp /= 9; if ((int)(temp * 10) % 10 >= 5) ++temp; arr[i][9] = temp; } for (i = 0; i a..
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fch729m%2FbtqJ3gSua2A%2F2VAI96RKdOqSzbdnxMsmh1%2Fimg.png)
[알고리즘 문제] 47. 봉우리
2020. 10. 3. 19:24
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, j, t, count = 0; cin >> n; vector vInt; vector vTemp; for (i = 0; i > t; vTemp.push_back(t); } } vInt.push_back(vTemp); } for (i = 1; i
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbqZSi4%2FbtqJ3ivBNKX%2FfiZB2k8OcUz66XCsw7Zl7K%2Fimg.png)
[알고리즘 문제] 46. 멀티태스킹(카카오 먹방 문제 변형)
2020. 10. 2. 22:31
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, i, k, temp = 0, idx = -1, sum = 0; cin >> n; vector vInt(n); for (i = 0; i > vInt[i]; sum += vInt[i]; } cin >> k; temp = 0; if (sum
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FDA7mg%2FbtqJXVaiXqg%2FWLx7zkl8Y6Cj0JxfyNgQTk%2Fimg.png)
[알고리즘 문제] 45. 공주 구하기
2020. 10. 2. 22:02
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int main(void) { int n, k, i, count = 0, idx = 0, size = 0, result = 0; cin >> n >> k; vector vBool(n); size = n; while (size > 1) { if (!vBool[idx]) { if (++count >= k) { vBool[idx] = true; --size; count = 0; } else result = idx; } if (++idx >= n) idx = 0; } cout
![thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FYAWiY%2FbtqJV6jk6wv%2F59Chc1EnFyRUUi3CIq6xKk%2Fimg.png)
[알고리즘 문제] 44. 마구간 정하기(이분검색 응용)
2020. 10. 2. 21:42
문제 풀이/알고리즘 문제풀이
코드 #include #include #include using namespace std; int count(const vector& vInt, const int size) { int i, prev = vInt[0], cnt = 2; for (i = 1; i = size) { ++cnt; prev = vInt[i]; } } return cnt; } int main(void) { int n, c, i, mid, res, temp; int left, right = 0; cin >> n >> c; vector vInt(n); for (i = 0; i > vInt[i]; right += vInt[i]; } ..