aboutsummaryrefslogtreecommitdiff
path: root/path_max_probability.cpp
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-08-26 18:27:42 -0600
committerJack Sangdahl <[email protected]>2024-08-26 18:27:42 -0600
commitfac51ecb29d9a3030f78d09c4e3243c1445bf78f (patch)
treebde2f8814cf61577234b471b78a25789df64f998 /path_max_probability.cpp
parente4802f322ee47adb92ea627efc39b2a6c3072cb4 (diff)
downloadleetcode-fac51ecb29d9a3030f78d09c4e3243c1445bf78f.tar.gz
leetcode-fac51ecb29d9a3030f78d09c4e3243c1445bf78f.zip
1514. path with maximum probability
Diffstat (limited to 'path_max_probability.cpp')
-rw-r--r--path_max_probability.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/path_max_probability.cpp b/path_max_probability.cpp
index 12eb644..0a64961 100644
--- a/path_max_probability.cpp
+++ b/path_max_probability.cpp
@@ -32,12 +32,11 @@ public:
int node = top.second;
if (!seen[node]) {
seen[node]++;
- for (auto to : vvp[node]) {
+ for (auto to : vvp[node])
if (mx[to.first] < to.second * prob_a) {
mx[to.first] = to.second * prob_a;
pqp.push({mx[to.first], to.first});
}
- }
}
}
return mx[end];
@@ -46,8 +45,8 @@ public:
int main() {
Solution obj;
- vvd(int) e = {{0, 1}, {1, 2}, {0, 2}};
+ vvd(int) e1 = {{0, 1}, {1, 2}, {0, 2}}, e2 = {{0, 1}, {1, 2}, {0, 2}};
vector<double> sp1 = {0.5, 0.5, 0.2}, sp2 = {0.5, 0.5, 0.3};
- printf("%f\n", obj.maxProbability(3, e, sp1, 0, 2)); // expect: 0.25000
- printf("%f\n", obj.maxProbability(3, e, sp2, 0, 2)); // expect: 0.30000
+ printf("%f\n", obj.maxProbability(3, e1, sp1, 0, 2)); // expect: 0.25000
+ printf("%f\n", obj.maxProbability(3, e2, sp2, 0, 2)); // expect: 0.30000
}