분류 전체보기 (131) 썸네일형 리스트형 101. 플로이드 워샬 알고리 (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★★☆☆ #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, a, b, c; cin >> n >> m; vector dis(n+1, vector(n+1, 5000)); for(int i = 1; i a >> b >> c; dis[a][b] = c; } for(int k = 1; k 100. 최대점수 구하기(냅색 알고리즘) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★☆☆☆ #include #include using namespace std; struct Exam { int score; int time; Exam(int x, int y) { this -> score = x; this -> time = y; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, a, b; cin >> n >> m; vector V; vector Scores(m+1, 0); V.push_back(Exam(0, 0)); for(int i = 0; i > a >> b; V.push_back(Exam(a, b)); } for(int i = 1; i = 0; j--) { if(j - exam.t.. 99. 동전교환(냅색 알고리즘) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★☆☆☆ #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, a; cin >> n; vector C; for(int i = 0; i > a; C.push_back(a); } cin >> m; vector V(m+1, 0); for(int i = 0; i V[j-C[i]] + 1 || V[j] == 0) V[j] = V[j-C[i]] + 1; } } cout 98. 가방문제(냅색 알고리즘) (it 취업을 위한 알고리즘 문제풀이 입문 (with C/C++) : 코딩테스트 대비) ★★☆☆☆ #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, a, b; cin >> n >> m; vector V; vector Bag(m+1, 0); for(int i = 1; i > a >> b; V.push_back(make_pair(a, b)); } for(int i = 0; i < V.size(); i++) { int w = V[i].first; int v = V[i].second; for(int j = 0; j < Bag.size(); j++) { if(j - w < 0) continue; if(Bag[j] < Bag[j-w] + v) Bag[j] = Bag[j-.. 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 이전 1 2 3 4 5 6 7 8 ··· 17 다음 목록 더보기