Skip to content

Commit

Permalink
pastbook2 typical_algorithm_c
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jun 15, 2023
1 parent 05fa217 commit d7b1bf9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions cargo-compete/pastbook2/Cargo.toml
Expand Up @@ -16,6 +16,7 @@ edition = "2018"
085 = { alias = "pastbook2022_b", problem = "https://atcoder.jp/contests/pastbook2022/tasks/pastbook2022_b" }
090 = { alias = "dp_n", problem = "https://atcoder.jp/contests/dp/tasks/dp_n" }
094 = { alias = "tdpc_iwi", problem = "https://atcoder.jp/contests/tdpc/tasks/tdpc_iwi" }
098 = { alias = "typical_algorithm_c", problem = "https://atcoder.jp/contests/typical-algorithm/tasks/typical_algorithm_c" }

[[bin]]
name = "027"
Expand Down
1 change: 1 addition & 0 deletions cargo-compete/pastbook2/README.md
Expand Up @@ -12,3 +12,4 @@
- P.85 編集距離 (オリジナル問題) <https://atcoder.jp/contests/pastbook2022/tasks/pastbook2022_b>
- P.90 Slimes (Educational DP Contest:N問題) <https://atcoder.jp/contests/dp/tasks/dp_n>
- P.94 イウィ (Typical DP Contest:I 問題) <https://atcoder.jp/contests/tdpc/tasks/tdpc_iwi>
- P.98 巡回セールスマン問題 (典型アルゴリズム問題集 C問題) <https://atcoder.jp/contests/typical-algorithm/tasks/typical_algorithm_c>
34 changes: 34 additions & 0 deletions cargo-compete/pastbook2/src/bin/098.rs
@@ -0,0 +1,34 @@
use std::collections::VecDeque;

use proconio::input;

fn main() {
input! {
n: usize,
a: [[usize; n]; n],
}
let inf = 1_usize << 60;
let mut dp = vec![vec![inf; n]; 1 << n];
dp[1 << 0][0] = 0_usize;
let mut deque = VecDeque::new();
deque.push_back((1 << 0, 0_usize));
while let Some((set, u)) = deque.pop_front() {
for v in 0..n {
if (set & (1 << v)) != 0 {
continue;
}
let new_set = set | (1 << v);
let new_cost = dp[set][u] + a[u][v];
if new_cost < dp[new_set][v] {
dp[new_set][v] = new_cost;
deque.push_back((new_set, v));
}
}
}
let mut min = inf;
for u in 1..n {
min = min.min(dp[(1 << n) - 1][u] + a[u][0]);
}
let ans = min;
println!("{}", ans);
}

0 comments on commit d7b1bf9

Please sign in to comment.