网址: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. lnmp 安装opencart出现open_basedir 错误解决办法

    php 在引用上级目录以外的文件时报错可以通过设置/usr/local/nginx/conf/fastcgi.conf

  2. C# 同步更新网盘和本地的文件夹及文件

    该程序是可以更新本地文件或更新网盘文件或者网盘和本地同步更新 下载地址:https://files.cnblogs.com/files/Wonderful-Life/UpdateFilesSync.r ...

  3. antd-design TextArea initialValue 不生效可能原因

    <Form.Item label="展会介绍"> {getFieldDecorator('introduce', { initialValue:record.intro ...

  4. PLS-00357: Table,View Or Sequence reference 'SEQ_TRADE_RECODE.NEXTVAL' not allowed in this context

    oracle数据库: 为了使ID自增,建了序列后,创建触发器: create or replace TRIGGER TRIG_INSERT_TRADE_RECODE BEFORE INSERT ON ...

  5. C++ STL标准容器插入删除算法的复杂度

    1 vector内部实现: 数组 // 就是没有固定大小的数组,vector直接翻译是向量的意思支持操作:begin(), //取首个元素,返回一个iteratorend(), //取末尾(最后一个元 ...

  6. day 06

    深浅拷贝 # 值拷贝:应用场景最多ls = [1, 'abc', [10]]​ls1 = ls  # ls1直接将ls中存放的地址拿过来# ls内部的值发生任何变化,ls1都会随之变化​ls2 = l ...

  7. Elasticsearch .net client NEST 5.x 使用总结

    目录: Elasticsearch .net client NEST 5.x 使用总结 elasticsearch_.net_client_nest2.x_到_5.x常用方法属性差异 Elastics ...

  8. ASP.NET MVC WebAPI Put和Delete请求出现405(Method not allowed)错误

    解决办法: 在站点根目录下的web.config设置如下(主要参考添加项): <system.webServer> <modules> <remove name=&quo ...

  9. Unity外包 UE4外包 项目案例平台开通通知

    长年承接Unity外包 UE4外包,大家好,本公司团队已将案例上传至专门的案例官网. 欢迎联系我们索取,谢谢! 有项目外包请联系QQ:372900288 索取案例.

  10. _spellmod_aura_pct

    属性光环 为玩家增加光环或降低属性 `aura`光环ID `auraType1` 配置属性('空','生命值','全属性','近战攻击强度','远程攻击强度','法术强度','治疗效果','施法速度' ...