본문 바로가기
반응형

분류 전체보기272

[알고리즘] c++ cpp 단지번호붙이기 포인트 1. bfs 에서 각 영역에 대하여 번호를 붙이는 방법을 보여준다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. #include #include #include #include #include using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int n; int map[26][26]; bool visited[26][26]; vector vc; void bfs(int a, int b) { queue q; q.push({a, b}); visited[a][b] = 1; int count = 1; while (!q.empty()) { int x, y; tie(x, y) = q.front(); q.pop(); fo.. 2020. 10. 28.
[알고리즘] 스탠다드 LCS - 최장 공통 부분 수열 최장 공통 부분 수열 문제는 다이나믹으로 해결을 할 수 있습니다. 이 문제는 편집거리 문제와 동일하게 해결을 할 수 있습니다. #include #include #include using namespace std; string str1, str2; int lcs[1001][1001]; int main() { string s1, s2; cin >> s1 >> s2; // LCS 알고리즘을 위해 앞에 '0'을 붙여준다. str1 = '0' + s1; str2 = '0' + s2; for (int i = 0; i < str1.size(); i++) { for (int j = 0; j < str2.size(); j++) { if (i == 0 || j == 0) { lcs[i][j] = 0; continue; }.. 2020. 10. 28.
[알고리즘] 스탠다드 BFS (너비 우선 탐색) 이 포스트는 너비 우선 탐색을 처음으로 접하는 분을 대상으로 합니다. 너비 우선 탐색은 그래프에서 사용할 수 있는 알고리즘 입니다. 처음 이해를 하실 때는 저는 `퍼지는 방향으로` 의 키워드를 잡고 이해를 했습니다. Queue 를 사용을 하여 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. #include #include #include using namespace std; vector map; vector visited; int n, m; int u, v; void bfs(int a) { //bfs 는 기본적으로 queue 를 사용한다. queue q; visited[a] = 1; q.push(a); while (!q.empty()) { int x = q.front(); q.pop(); cou.. 2020. 10. 28.
[알고리즘] c++ cpp 방의 개수 포인트 1. map 을 사용하여 방문상태와 연결 상태를 확인한다. 🧶문서는 항상 수정 될 수 있습니다. 비판은 환영합니다. #include #include using namespace std; int dx[8]={ -1, -1, 0, 1, 1, 1, 0, -1 }; int dy[8]={ 0, 1, 1, 1, 0, -1, -1, -1 }; struct Point { int x, y; }; int solution (vector arrows) { int room=0; map visited; map connected; Point point={ 0,0 }; visited[{point.x, point.y}]=1; for (int i=0; i < arrows.size (); i++) { // point.x자의 교차 .. 2020. 10. 24.
반응형