Skip to content

Latest commit

Β 

History

History

P2098

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 

[baekjoon-2098] μ™ΈνŒμ› 순회

image

μ™ΈνŒμ› 순회 문제

μ™ΈνŒμ› 순회 λ¬Έμ œλŠ” λΉ„νŠΈλ§ˆμŠ€ν¬ + DP λ₯Ό μ΄μš©ν•œ λ¬Έμ œμ΄λ‹€. 풀이 및 μ½”λ“œλ₯Ό μ΄ν•΄ν•œ ν›„, μ™Έμš°λŠ” 것이 쒋은 것 κ°™λ‹€.

int TSP(int mask, int now) {
    if (mask == (1<<N)-1) {
        if (W[now][0] > 0) return W[now][0];
        return INF;
    }

    if (dp[mask][now] != INF) return dp[mask][now];
    for (int i = 0; i < N; i++) {
        if ((mask & 1<<i) == 0 && W[now][i] > 0) {
            dp[mask][now] = Math.min(dp[mask][now], TSP(mask|1<<i, i) + W[now][i]);
        }
    }
    return dp[mask][now];
}

image