프로그래밍74 [bfs, dfs] 백준 2573 빙산 https://www.acmicpc.net/problem/2573 bfs 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687#include #include using namespace std; int map[300][300] = {0};int dx[4] = {1,-1,0,0};int dy[4] = {0,0,1,-1};int n,m; bool bfs_chk(){ int cnt = 0; bool visited[300][300] = {0}; queue q; for(in.. 2019. 3. 25. [bfs, dfs] 백준 2667 단지번호붙이기 https://www.acmicpc.net/problem/2667 저에게 익숙한 bfs로 짠 코드 입니다.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#include #include #include using namespace std; int main(){ char map[25][25]; int ret[625] = {0}; int n, idx= -1; queue q; bool visited[25][25] = {0}; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; cin >> n; for(int i = 0; i map[i][j]; }.. 2019. 3. 24. [dfs] 백준 2606 바이러스 https://www.acmicpc.net/problem/2606 123456789101112131415161718192021222324252627282930313233343536373839404142#include #include using namespace std; int ret = 0;vector v[101];bool visited[101] = {0}; void dfs(int start); int main(){ ios_base::sync_with_stdio(false); int com_n, n; cin >> com_n >> n; for(int i = 0; i > x >> y; v[x].push_back(y); v[y].push_back(x); } dfs(1); cout 2019. 3. 22. [bfs] 백준 7569 토마토 https://www.acmicpc.net/problem/7569 처음에 토마토가 들어가 있는 좌표를 queue에 push합니다. 그리고 queue에 있는 것을 하나 씩 꺼내서 bfs합니다. 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970#include #include using namespace std; int map[100][100][100];int h,n,m; bool chk(){ for(int i = 0; i > n >> h; for(int i = 0; i 2019. 3. 22. [bfs] 라비다 1052 maze problem https://judge.lavida.us/problem.php?id=1052 아주대 A.N.S.I에서 쓰는 저지 사이트입니다. 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758#include #include using namespace std; int main(){ ios_base::sync_with_stdio(false); int t; int dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; cin >> t; while(t--){ char map[100][100]; int n,m; pair start; cin >> n >> m; f.. 2019. 3. 18. [dp] 백준 1495 기타리스트 https://www.acmicpc.net/problem/1495 다이나믹 프로그래밍을 이용헤서 풀었습니다. dp를 이차원 배열로 해서 그 곡에 가능한 볼륨을 체크하는 방식으로 풀었습니다. 12345678910111213141516171819202122232425262728293031#include using namespace std; int main() { int n, s, m; bool dp[101][10001] = { {0,}, }; int v[101]; int ret = -1; cin >> n >> s >> m; for (int i = 1; i > v[i]; if (s - v[1] >= 0) dp[1][s-v[1]] = true; if (s + v[1] 2019. 2. 20. 이전 1 2 3 4 5 6 7 ··· 13 다음