본문 바로가기

알고리즘/완전 탐색13

백준 11724번 : 연결 요소의 개수 문제 링크 : www.acmicpc.net/problem/11724 내 풀이(2021.1.3.) : #include #include using namespace std; int visit[1001] = { 0, }; int edge[1001][1001] = { 0, }; int N, M; int cnt = 0; void BFS(int root) { if (visit[root] == 1) return; visit[root] = 1; cnt++; queue q; q.push(root); while (!q.empty()) { int n = q.front(); q.pop(); for (int i = 1; i > N >> M; for (int i = 0; i > u.. 2021. 1. 3.
백준 1012번 : 유기농 배추 문제 링크 : acmicpc.net/problem/1012 내 풀이(2021. 1. 2.) : #include using namespace std; bool exist[50][50]; bool visit[50][50]; int counts = 0; int X, Y, K; void search(int y, int x, bool first) { if (y == -1 || x == -1 || y == Y || x == X) return; if (exist[y][x] == false) return; if (visit[y][x] == true) { return; } else { if (first == true) { counts++; first = false; } } visit[y][x] = true; search.. 2021. 1. 2.
BFS 개념 참고 : coding-factory.tistory.com/612 인접 행렬은 노드들 간의 연결 관계가 많을 때 인접 리스트는 노드들 간의 연결 관계가 적을 때 사용한다. Node가 N개이면 Edge의 최대 개수는 1+2+ ... + (N-1) = N(N-1)/2 2020. 12. 21.
백준 1074번 : Z 문제 링크 : www.acmicpc.net/problem/1074 풀이에 참고한 링크 : www.acmicpc.net/board/view/46542 내 풀이 (2020.12.17.) : #include #include using namespace std; int N, R, C; int cnt = 0; void search(int N, int r, int c) { if (N == 0) { if(R == r && C == c){ cout > N >> R >> C; search(N, 0, 0); } 결과 : 시간 초과 이 풀이의 시간복잡도는 O(2^2N)인데 N이 최대 15이므로 최대 걸리는 시간은 2^30 = 10,0000,0000 (10초) 이다. 내 풀이2 (2020.12.17.) : #include #.. 2020. 12. 17.