Skip to content

Conversation

@esc10946
Copy link
Contributor

@esc10946 esc10946 commented Jan 4, 2026

🚀 이슈 번호

Resolve: {#2270}

🧩 문제 해결

스스로 해결:

🔎 접근 과정

문제 해결을 위한 접근 방식을 설명해주세요.

  • 🔹 어떤 알고리즘을 사용했는지 : dp
  • 🔹 어떤 방식으로 접근했는지 : 밑변을 기준으로 정렬 해보니까 무게를 기준으로 LIS의 dp방식으로 풀면 풀리길래 해당 dp를 변형해서 풀게 되었다

⏱️ 시간 복잡도

시간 복잡도 분석을 작성해주세요.
최악의 경우 수행 시간은 어느 정도인지 분석합니다.

  • Big-O 표기법: O(N^2)
  • 이유: 배열 전체를 순회하고 해당 인덱스 까지 한번 더 순회하여서 N^2의 시간 복잡도를 가짐

💻 구현 코드

#include <bits/stdc++.h>

using namespace std;

struct Brick {
    int id;      // 원래 벽돌 번호
    int area;
    int height;
    int weight; 
};
bool compare(const Brick& a, const Brick& b) {
    return a.area > b.area;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vector<Brick> bricks(n);

    for (int i = 0; i < n; i++) {
        bricks[i].id = i + 1;
        cin >> bricks[i].area >> bricks[i].height >> bricks[i].weight;
    }

    sort(bricks.begin(), bricks.end(), compare);

    vector<int> dp(n, 0);
    vector<int> trace(n, -1);

    int max_height = 0;
    int last_idx = -1;

    for (int i = 0; i < n; i++) {
        dp[i] = bricks[i].height;
        for (int j = 0; j < i; j++) {
            if (bricks[j].weight > bricks[i].weight) {
                if (dp[j] + bricks[i].height > dp[i]) {
                    dp[i] = dp[j] + bricks[i].height;
                    trace[i] = j;
                }
            }
        }
        if (dp[i] > max_height) {
            max_height = dp[i];
            last_idx = i;
        }
    }

    vector<int> result;
    int curr = last_idx;
    while (curr != -1) {
        result.push_back(bricks[curr].id);
        curr = trace[curr];
    }

    cout << result.size() << "\n";
    for (int id : result) {
        cout << id << "\n";
    }

    return 0;
}

@esc10946 esc10946 linked an issue Jan 4, 2026 that may be closed by this pull request
@esc10946 esc10946 changed the title Add files via upload 260105 : [BOJ 2655] 가장높은탑쌓기 Jan 8, 2026
@esc10946 esc10946 merged commit 9492696 into main Jan 12, 2026
1 of 2 checks passed
@esc10946 esc10946 deleted the hojun/2270/1 branch January 12, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

260105 : 코딩테스트

2 participants