tipstar0125 / atcoder

atcoder
6 stars 0 forks source link

bitDP #51

Open tipstar0125 opened 10 months ago

tipstar0125 commented 10 months ago

dp[s][pos]:= 集合s(bitが1がvisited)のとき、posにいるときの最小

MAX=1<<L
dp=[[INF for _ in range(L)] for _ in range(MAX)]
dp[0][0]=0

for s in range(1,MAX):
    for frm in range(L):
        if frm!=0 and s&(1<<frm)==0:continue  # 原点0に戻る場合
        # if s&(1<<frm)==0:continue  # 戻らない場合
        for to in range(L):
            if s&(1<<to)==0:continue
            bs=s^(1<<to)
            dp[s][to]=min(dp[s][to],dp[bs][frm]+dist[frm][to])

問題:https://atcoder.jp/contests/abc274/tasks/abc274_e 解答:https://atcoder.jp/contests/abc274/submissions/49806227

問題:https://atcoder.jp/contests/abc301/tasks/abc301_e 解答:https://atcoder.jp/contests/abc301/submissions/49787905

tipstar0125 commented 10 months ago
tipstar0125 commented 10 months ago

問題リスト https://blog.hamayanhamayan.com/entry/2017/07/16/130151