백준

    [실1] 1074 - Z

    #include #include #include #include #include #include #include #pragma warning(disable : 4996) using namespace std; int n, r, c, ans = 0; void dc(int x, int y, int size) { if (c == x && r == y) { cout = x && r >= y) { auto half = size / 2; dc(x, y, half); dc(x + half, y, half); dc(x, y + half, half); dc(x + half, y + half, half); } else ans += pow(size, 2); } int main() { ios::sync_with_stdio(0)..

    [실1] 1697 - 숨바꼭질

    for 범위 기반 임시 초기화 리스트를 이용해서 푼게 핵심이다. #include #include #include #include #include using namespace std; int dist[100002]; int n, k; int main() { ios::sync_with_stdio(0); cin.tie(0); fill(dist, dist + 100001, -1); cin >> n >> k; dist[n] = 0; queue q; q.push(n); while (dist[k] == -1) { int cur = q.front(); q.pop(); for (int nxt : {cur - 1, cur + 1, cur * 2}) { if (nxt 100000) continue; ..

    [골5] 2170 - 선 긋기

    #include #include #include #include using namespace std; #define y first #define x second bool cmp(pair& lRef, pair& rRef) { return lRef.y > n; vector v(n); for (int i = 0; i > v[i].y >> v[i].x; sort(v.begin(), v.end(), cmp); int s = INT_MIN, e = INT_MIN, ans = 0; for (int i = 0; ..

    [실1] 9465 - 스티커

    #include #include #include #include #include using namespace std; int main() { int c; cin >> c; while(c--) { int n; cin >> n; n++; vector dp(n, vector(n + 1)); for (int i = 1; i > dp[0][i]; for (int i = 1; i > dp[1][i]; for (int i = 2; i < n; i++) { dp[0][i] += max(dp[1][i - 1], dp[1][i - 2]); dp[1][i] += max(dp[0][i - 1], dp[0][i - 2]); } cout

    [골4] 9252 - LCS 2

    #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); string str1, str2; cin >> str1 >> str2; str1 = ' ' + str1; str2 = ' ' + str2; int n = str1.size(), m = str2.size(); vector v(n, vector(m)); stack s; for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { if (str1[i] == str2[j]) v[i][j] = v[i - 1][j - 1] + 1; ..

    [실1] 15724 - 주지수

    #include #include using namespace std; #define SIZE 1050 int n, m, t, arr[SIZE][SIZE]{ 0 }; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i a; arr[i][j] = a + arr[i - 1][j] + arr[i][j - 1] - arr[i - 1][j - 1]; } } cin >> t; while (t--) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; cout

    [실4] 1120 - 문자열

    #include #include #include using namespace std; int main() { string a, b; cin >> a >> b; int aLength = a.size(), bLength = b.size(); int res = INT_MAX; for (int i = 0; i

    [실4] 3986 - 좋은 단어

    #include #include #include using namespace std; int main() { int n, res = 0; cin >> n; while(n--) { string str; cin >> str; stack s; for (int i = 0; i < str.size(); i++) { if(!s.empty() && s.top()==str[i]) { s.pop(); continue; } s.push(str[i]); } if (s.empty()) res++; } cout

    [실2] 11725 - 트리의 부모 찾기

    #include #include #include #include using namespace std; #define MAX_SIZE 100001 vector graph[MAX_SIZE]; int arr[MAX_SIZE]; bool vis[MAX_SIZE]; int main() { int n; cin >> n; for (int i = 1; i > y >> x; graph[y].push_back(x); graph[x].push_back(y); } stack s; s.push(1); vis[1] = true; while (!s.empty()) { auto idx = s.top(); s.pop(); for (int i = 0; i < graph[idx].size(..

    [실3] 15654 - N과 M (5)

    #include #include #include using namespace std; #define MAX 9 vector v; int arr[MAX]{ 0 }; bool vis[MAX]{ 0 }; int n, m; void dfs(int idx) { if (idx == m) { for (int i = 0; i m; v.resize(n); for (int i = 0; i > v[i]; sort(v.begin(), v.end()); dfs(0); }