[C++] 백준 1697 숨바꼭질 BFS
·
Algorithm/Baekjoon
#include #include #define MAX_LOCATION 100001 using namespace std; int K, N; int visited[MAX_LOCATION]{false}; void BFS(int curr); int main() { ios::sync_with_stdio(false); cin >> N >> K; BFS(N); } void BFS(int curr) { queue q; q.push({ curr, 0 }); visited[curr] = true; while (!q.empty()) { int currNode = q.front().first; int currSec = q.front().second; q.pop(); if (currNode == K) { cout currNod..
[C++] 백준 1260 DFS와 BFS
·
Algorithm/Baekjoon
#include #include #include #include #include using namespace std; const int vertexMax = 1001;//최대 노드 개수 vector num[vertexMax]; bool visited[vertexMax]{false};//방문한 노드 void DFS(int curr); void BFS(int curr); int main() { ios::sync_with_stdio(false); int vertex, line, startNum; cin >> vertex >> line >> startNum; for (int i = 0; i > temp[0] >> temp[1]; num[temp[0]]...
[C++] 백준 2655 가장높은탑쌓기 DP
·
Algorithm/Baekjoon
#include #include #include #include #define BLOCK_MAX 101 using namespace std; struct BlockInfo { int index; int area; int height; int weight; }; bool Sorted(BlockInfo &x, BlockInfo &y); int main() { ios::sync_with_stdio(false); int dp[BLOCK_MAX]{0}; int n, max_height = 0; cin >> n; vector blocks(n + 1); vector result; blocks[0] = { 0 }; for (int i = 1; i > blocks[i].area >> blocks[i].height >> ..
[C++] 백준 1495 기타리스트 DP
·
Algorithm/Baekjoon
#include #include #define MAX_MUSIC 101 #define MAX_VOLUME 1001 using namespace std; int main() { ios::sync_with_stdio(false); int N, S, M, result = -1; cin >> N >> S >> M; int volume[MAX_MUSIC]; bool max[MAX_MUSIC][MAX_VOLUME]; for (int i = 1; i > volume[i]; max[0][S] = true;//첫번째값 for (int i = 0; i < N; i++) { for (int j = 0; j = 0; j--) { if (max[N][j] == true) { result = j; break; } } cout
[C++] 백준 9251 LCS
·
Algorithm/Baekjoon
#include #include #include #include using namespace std; string x, y; int dp[1001][1001]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); getline(cin, x); getline(cin, y); for (int i = 1; i
[C++] 백준 11053 가장 긴 증가하는 부분 수열
·
Algorithm/Baekjoon
#include #include #include using namespace std; int n, maxNum = 0; vector num; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > temp; num.push_back({temp, 1}); } for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (num[j].first < num[i].first) { num[i].second = max(num[i].second, num[j].second + 1); } } maxNum = max(maxNum..