网址:https://leetcode.com/problems/minimum-cost-for-tickets/

参考:https://leetcode.com/problems/minimum-cost-for-tickets/discuss/226659/Two-DP-solutions-with-pictures

class Solution
{
public:
int mincostTickets(vector<int>& days, vector<int>& costs)
{
unordered_set<int> travel(begin(days), end(days));
vector<int> dp(days.back()+,);
for(int i=; i<days.back()+; i++)
{
if(travel.find(i) == travel.end())
dp[i] = dp[i-];
else
{
dp[i] = min(dp[i-]+costs[], dp[max(, i-)]+costs[], dp[max(, i-)]+costs[]);
}
}
return dp[days.back()];
}
};

983. Minimum Cost For Tickets的更多相关文章

  1. LeetCode 983. Minimum Cost For Tickets

    原题链接在这里:https://leetcode.com/problems/minimum-cost-for-tickets/ 题目: In a country popular for train t ...

  2. LC 983. Minimum Cost For Tickets

    In a country popular for train travel, you have planned some train travelling one year in advance.  ...

  3. 【leetcode】983. Minimum Cost For Tickets

    题目如下: In a country popular for train travel, you have planned some train travelling one year in adva ...

  4. Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)

    Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...

  5. 【LeetCode】983. 最低票价 Minimum Cost For Tickets(C++ & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetco ...

  6. [Swift]LeetCode983. 最低票价 | Minimum Cost For Tickets

    In a country popular for train travel, you have planned some train travelling one year in advance.  ...

  7. Minimum Cost For Tickets

    In a country popular for train travel, you have planned some train travelling one year in advance.  ...

  8. Minimum Cost(最小费用最大流)

    Description Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his s ...

  9. POJ 2516 Minimum Cost (费用流)

    题面 Dearboy, a goods victualer, now comes to a big problem, and he needs your help. In his sale area ...

随机推荐

  1. 一个handle使用更新线程的实例

    handle更新线程实例 package com.example.administrator.handle; import android.app.Activity;import android.os ...

  2. To My Girlfriend (DP)

    题意:求选中若干个数,满足和为S,且不能选中下表i, j 和选中k, l的情况总数量. 思路:DP[i][j][k][l] i:前i个和为j,选中k个和不选中l个的情况数量,那么我们的转换应该是在必选 ...

  3. TypeError: '_io.TextIOWrapper' object does not support item assignment

    纯小白 遇到的细节问题: 报错 一开始看到这个傻逼了 TypeError: '_io.TextIOWrapper' object does not support item assignment 其实 ...

  4. 网络-04-端口号-linux端口详解大全--TCP注册端口号大全

    # John Murphy <john.m.murphy&mci.com>afs3-fileserver 7000/tcp file server itselfafs3-files ...

  5. mysql8操作命令(持续更新)

    mysql服务管理 查看服务状态 systemctl status mysqld.service 启动服务 systemctl start mysqld.service 关闭服务 systemctl ...

  6. postman工具的使用

    https://www.cnblogs.com/rookie-c/p/5753948.html#4100341 https://www.jellythink.com/archives/category ...

  7. react-native 导航器 react-navigation 3.x 使用

    React-navigation 介绍 React Navigation 源于 React Native 社区对一个可扩展且易于使用的导航解决方案的需求,它完全使用 JavaScript 编写. (如 ...

  8. shell之for和if实现批量替换多目录下的文件

    问题背景: 生产环境的项目图片文件夹众多,每个项目都会有一个图片文件夹,现在要批量替换每个文件夹下的一张模板图片 如图,我们要替换每一个文件夹下的01.jpg shell 脚本 #/bin/bash ...

  9. Android中碎片的添加问题

    碎片在Android中的应用是十分广泛的,它就像是嵌在活动中的另一个活动就像是一个容器包含了另一个容器,那么到底该怎么添加碎片呢?主要有两种方法,一种是在该碎片所在的xml文档中使用Android:n ...

  10. python自学day1

    1.是区别Windows和linux在Python编码时不同: 在linux中,Python编码要在首行加入 #! /usr/bin/env python   指定编译的位置,而在Windows时中不 ...