Advertisement

LeetCode K站中转最便宜航班(DP解法)

阅读量:

(https://leetcode-cn.com/problems/cheapest-flights-within-k-stops/ "题目链接")

[题目链接](https://leetcode-cn.com/problems/cheapest-flights-within-k-stops/"' 题目链接')

(https://leetcode-cn.com/problems/cheapest-flights-within-k-stops/"' 题目链接')

这个题目确实耗费了不少时间和精力。由于缺乏对这类问题如最短路径或最佳路线等基础题型的理解,我一开始对其解答方法感到十分困惑,因此一直未能掌握动态规划问题的解决思路,自然无法找到解题突破口。不过,这次经历既作为自我反思的一个记录本体存在,也是一次学习过程中的经验总结。

先将程序贴在这:

复制代码
 class Solution {

    
 public:
    
     int findCheapestPrice(int n, vector<vector<int>>& flights, int src, int dst, int K) {
    
     //dp[i][k]表示从src至多经过k站到达i的最少费用
    
     vector<vector<int>> dp(n, vector<in

全部评论 (0)

还没有任何评论哟~