본문 바로가기

CodingTest Exam

(110)
97. 알리바바와 40인의 도둑(Top-Down) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★☆☆ #include using namespace std; int a[20][20]; int dy[20][20]; int n; void DFS(int x, int y, int sum) { if(x == n) return; if(y == n) return; if(dy[x][y] == 0) { dy[x][y] = sum; } else { if(dy[x][y] > sum) dy[x][y] = sum; } DFS(x+1, y, sum + a[x+1][y]); DFS(x, y+1, sum + a[x][y+1]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 0; i < n; i++) { for(int j = 0..
96. 알리바바와 40인의 도둑(Bottom-Up) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★☆☆☆ #include #include using namespace std; int dy[20][20]; int a[20][20]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, p1 = 0, p2 = 0; cin >> n; int X[2] = {0, 1}; int Y[2] = {1, 0}; for(int i = 0; i > a[i][j]; } } dy[0][0] = a[0][0]; while(true) { if(p1 >= n || p2 >= n) break; for(int i = 0; i < 2; i++) { if(dy[p1+X[i]][p2+Y[i]] ..
95. 가장 높은 탑 쌓기 (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★☆☆ #include #include #include using namespace std; int dy[100]; struct Block { int r; int h; int m; Block(int x, int y, int z) { this -> r = x; this -> h = y; this -> m = z; } bool operator a.r; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, a, b, c, res = 0; cin >> n; vector V; for(int i = 0; i > a >> b >> c; V.push_back(Block(a, b, c)); } sort(V.begin()..
94. 최대 선 연결하기 (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★☆☆ #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, p1 = 1, p2 = 1, cnt = 0; cin >> n; vector a(n+1, 0); vector ch(n+1, 0); for(int i = 1; i > a[i]; } while(p1 max) { max = dy[j]; } } dy[i] = max + 1; if(dy[i] > res) res = dy[i]; } cout
93. 최대 부분 증가수열 (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★☆☆ #include using namespace std; int a[1000]; int dy[1000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m = 0, res = 0; cin >> n; for(int i = 1; i > a[i]; } dy[1] = 1; for(int i = 2; i = 1; j--) { if(a[j] max) max = dy[j]; } dy[i] = max + 1; if(dy[i] > res) res = dy[i]; } cout
92. 네트워크 선 자르기(동적계획법_ Top-Down : 재귀, 메모이제이션) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★☆☆ #include using namespace std; int dy[50]; int DFS(int x) { if(x == 1) { dy[x] = 1; return dy[x]; } if(x == 2) { dy[x] = 2; return dy[x]; } else { if(dy[x] != 0) { return dy[x]; } else { return dy[x] = DFS(x-2) + DFS(x-1); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; DFS(n); cout
91. 네트워크 선 자르기(동적계획법_Bottom-Up 기법) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★★☆ #include using namespace std; int dy[50]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; dy[1] = 1; dy[2] = 2; for(int i = 3; i
90. 라이언 킹 심바(삼성 SW역량평가 기출 : BFS 활용) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★★★ #include #include using namespace std; int a[26][26]; int ch[26][26]; struct Pos { int x; int y; int dis; Pos(int x, int y, int z) { this -> x = x; this -> y = y; this -> dis = z; } bool operator a.y; else return x > a.x; } else return dis > a.dis; } }; struct Simba { int x; int y; int size; int cnt; void SizeUp() { cnt = 0; size++; } }; int main() { int n, res = 0; scanf("%d", &n); int dx[4] = ..