PTT
Submit
Submit
选择语言
正體中文
简体中文
PTT
Marginalman
Re: [闲聊] 每日leetcode
楼主:
oin1104
(是oin的说)
2024-08-27 11:35:09
引述《enmeitiryous (enmeitiryous)》
题目:
1514. Path with Maximum Probability
给你一个图有n个点,并给你一个vector:edge,每一个edge(u,v)的weight是从
u到v的成功机率(0<=w<=1),给定起始点s和终点d,求s到d的成功率最大路径
思路:
因为是无向图
比较姆咪一点
我用Dijkstra's
每次都往四周看
然后把可以走的地方丢到pq里面
这次有记得用priority queue 了
丢进去一直边走边看就可以了
姆咪
```cpp
class Solution {
public:
double maxProbability(int n, vector<vector<int>>& edges, vector<double>& suc
cProb, int start_node, int end_node)
{
vector<vector<pair<int,double>>> path(n);
vector<double> paper(n,0);
int len = edges.size();
for(int i = 0 ; i < len ; i ++)
{
path[edges[i][1]].push_back({edges[i][0] , succProb[i]});
path[edges[i][0]].push_back({edges[i][1] , succProb[i]});
}
priority_queue<pair<double,int>> pq;
pq.push({1,start_node});
while(!pq.empty())
{
int dest = pq.top().second;
double prob = pq.top().first;
pq.pop();
if(paper[dest] >= prob)continue;
if(dest == end_node)return prob;
paper[dest] = prob;
for(auto k : path[dest])
{
int next = k.first;
double nextprob = k.second;
pq.push({prob*nextprob , next});
}
}
return paper[end_node];
}
};
```
作者:
JIWP
(JIWP)
2024-08-27 11:36:00
姆咪我一开始没用heap,内存爆掉,太苦了
楼主:
oin1104
(是oin的说)
2024-08-27 11:38:00
你就是还没送我模型才会忘记用heap 你有什么用
作者:
JIWP
(JIWP)
2024-08-27 11:39:00
" target="_blank" rel="noreferrer noopener nofollow">
给你看蕾米的灯笼裤
楼主:
oin1104
(是oin的说)
2024-08-27 11:40:00
谢谢可以让他跟妹妹在一起吗就在旁边而已 我看到了两个一起拍照
作者:
JIWP
(JIWP)
2024-08-27 11:41:00
" target="_blank" rel="noreferrer noopener nofollow">
楼主:
oin1104
(是oin的说)
2024-08-27 11:41:00
干 好漂亮 这家叫什么
作者:
JIWP
(JIWP)
2024-08-27 11:42:00
alter
楼主:
oin1104
(是oin的说)
2024-08-27 11:45:00
推荐那个灵梦模型
作者:
JIWP
(JIWP)
2024-08-27 11:47:00
蛤?
继续阅读
[姆咪] 订了明天的机票
l00011799z
[瓦特] 蛋糕姬一张
Haku1Koyor1
[闲聊] 难怪我爸是赖粉
Leaflock
Re: [闲聊] 4060的显卡:0
mayolan
Re: [边缘] 跟阿芬约棒球约会 好紧张
wu10200512
[取暖] 中午吃水饺还是牛肉面
NekomataOkay
Re: [闲聊] 还是其实我的品味很烂
cities516
→ ILoverika : 误会 我不是甲
babagorou
[姆咪] 别的部门的主管
jjf0323
Re: [闲聊] 家人们 帮忙看一下我的品味
Leaflock
Links
booklink
Contact Us: admin [ a t ] ucptt.com