给你n个物品交换,每个交换用r,v,t描述,代表需要用r元的东西花费t时间交换得v元的东西。一开始只有1元的东西,让你求出交换到价值至少为m的最少时间代价。
相当于每个交换是一条边,时间为边权,求走到价值大于等于m的点的最短路径。bfs的时候,用优先队列来储存状态,每次取出花费总时间最小的状态。#include#include #include #include #define ll long longusing namespace std; struct node{ int r,v; ll t;}a[100005]; int n,m,cas; int cmp(const node &a, const node &b){ return a.r b.t; }}; priority_queue , cmp2>q; ll bfs(){ int l=1,i; q.push((node){ 0,1,0}); while(!q.empty()){ node s=q.top(); q.pop(); if(s.v>=m) return s.t; for(i=l;i<=n;i++){ if(s.v>=a[i].r&&s.v