<aside> 💡

완전탐색 시 시간을 줄여야 할 때는 봤던 곳을 또 보지 않는 방법을 생각해보자 dp를 사용해볼 수도 있고..

</aside>

<aside> 💡

DP 무적법칙: 문제가 해결이 안 될 것 같으면 차원을 늘려라

</aside>

<aside> 💡

시간복잡도가 중요한 문제: 누적합, 투포인터, 이분탐색, 스택

</aside>

<aside> 💡

큐, 스택 이런거에서 원소 뺄 땐 꼭…….. 비어있는지부터 확인하자… ha..

</aside>

<aside> 💡

그리디하게 푸는 방법이 늘 옳을까? 아닌 것 같으면 완전탐색+가지치기는 어떨지 생각해보자

</aside>

<aside> 💡

for(int j = max; j--; j >= 0)

서영아 이건 뭐냐.. 코테에서 이랬으면 레전드다 진짜

</aside>

<aside> 💡

using namespace std; 앞에 코드 쓰는 불상사 없게 하자

</aside>

<aside> 💡

priority queue 비교함수 커스텀 (맨날까먹음ㅋㅋ)

struct compare{
    bool operator()(const stock a, const stock b){
        return a.price < b.price;
    }
};

</aside>

<aside> 💡

백트래킹 시에 visit 위치 신경써주자

void dfs(int x, int y, int t) {
    if (x == n-1 && y == m-1) {
        minn = min(minn, t);
        return;
    }
    visited[x][y] = true;
    if (islands[x][y] == 0) return;
    for(int k = 1; k <= 4; k++) {
        int nx = x + dx[k];
        int ny = y + dy[k];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (visited[nx][ny]) continue;
        if (islands[x][y] == k) {
            dfs(nx, ny, t + 1);
        } else if (islands[x][y] > k) {
            dfs(nx, ny, t + 1 + k + 4 - islands[x][y]);
        } else {
            dfs(nx, ny, t + 1 + k - islands[x][y]);
        }
    }
    visited[x][y] = false;
}

return 종료조건 후에 true를 해줘야 함. 안그러면 visited가 false인 채 계속 돎 ㅠㅠ

</aside>

알고리즘 고득점 kit

완전탐색 2개 (Lv. 3 3)