Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitDP #51

Open
tipstar0125 opened this issue Jan 28, 2024 · 2 comments
Open

bitDP #51

tipstar0125 opened this issue Jan 28, 2024 · 2 comments

Comments

@tipstar0125
Copy link
Owner

tipstar0125 commented Jan 28, 2024

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])
  • TSP(原点に戻る)
    • 初期化において、dp[0][0]=0として、どこも訪れていない状態を0とする

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

  • TSP(原点に戻らない)
    • 初期化において、dp[1][0]=0として、原点を訪れた状態を0とする
    • 多始点の場合はdp[1<<i][i]として、全ての点で初期化する

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

@tipstar0125
Copy link
Owner Author

tipstar0125 commented Jan 28, 2024

@tipstar0125
Copy link
Owner Author

tipstar0125 commented Jan 30, 2024

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

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

No branches or pull requests

1 participant