link

题意:乘车,有3种票

1.20块坐1站

2.坐90分钟,50块

3.坐1440分钟,120块

现给出到达每个站的时间,问最优策略

思路: 简单DP,限定条件的3个转移方向,取最小的那个就行了

dp[i]代表到达第i个站的最小花费

/** @Date    : 2017-04-10 18:19:53
* @FileName: 760D dp.cpp
* @Platform: Windows
* @Author : Lweleth (SoundEarlf@gmail.com)
* @Link : https://github.com/Lweleth
* @Version : $Id$
*/
#include<bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int a[N];
int dp[N];
int main()
{
int n;
cin >> n;
dp[0] = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d", a + i);
int s = INF, t = INF;
dp[i] = dp[i - 1] + 20;
for(int j = i - 1; j >= 1; j--)
{
if(a[j] > a[i] - 90)
s = dp[j - 1] + 50;
if(a[j] > a[i] - 1440)
t = dp[j - 1] + 120;
if(a[i] - a[j] >= 1440)
break;
}
dp[i] = min(dp[i], min(s, t));
printf("%d\n", dp[i] - dp[i - 1]);
//system("pause");
}
return 0;
}

CF760 D Travel Card 简单DP的更多相关文章

  1. Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card

    D - Travel Card 思路:dp,类似于单调队列优化. 其实可以写的更简单... #include<bits/stdc++.h> #define LL long long #de ...

  2. 【二分】【动态规划】Codeforces Round #393 (Div. 1) B. Travel Card

    水dp,加个二分就行,自己看代码. B. Travel Card time limit per test 2 seconds memory limit per test 256 megabytes i ...

  3. Travel Card

    Travel Card time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  4. HDU 1087 简单dp,求递增子序列使和最大

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. Codeforces Round #260 (Div. 1) A. Boredom (简单dp)

    题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...

  6. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  7. 简单dp --- HDU1248寒冰王座

    题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...

  8. poj2385 简单DP

    J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit ...

  9. hdu1087 简单DP

    I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     ...

随机推荐

  1. 【树上DFS】Tree and Polynomials

    http://codeforces.com/gym/101372 D push1[i][k]:所有操作1总共要让节点i下推多少系数k push2[i][k]:所有操作2总共要让节点i上推多少系数k s ...

  2. 团队Alpha冲刺(九)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  3. 搜索引擎Elasticsearch,了解一下?

    ElasticSearch介绍 ElasticSearch是一个全文搜索服务器,也可以作为NoSql数据库,存储任意格式的文档和数据,同时可以做大数据的分析.ElasticSearch具有以下特点: ...

  4. java——线性表接口实现

    线性表是存储顺序牌类的数据时最常用的数据结构. 实现线性表有两种方式.第一种是使用数组存储线性表的元素.数组是动态创建的.超过数组的容量时,创建一个 新的更大的数组,并且将当前数组中的元素复制到新建的 ...

  5. 新手必备!11个强大的 Visual Studio 调试技巧

    简介 调试是软件开发周期中很重要的一部分.它具有挑战性,同时也很让人疑惑和烦恼.总的来说,对于稍大一点的程序,调试是不可避免的.最近几年,调试工具的发展让很多调试任务变的越来越简单和省时. 这篇文章总 ...

  6. 【转载】mysql建表date类型不能设置默认值

    如题,mysql建表date类型的不能设置一个默认值,比如我这样: CREATE TABLE `new_table` ( `biryhday` datetime NULL DEFAULT '1996- ...

  7. 【Nginx】均衡负载权重模式实现session数据同步

    思路:把session存放到一个公共redis服务器上 每次浏览器请求服务端都会带上cookie,因为使用的是权重负载均衡方案,因此nginx反向代理服务器会把请求发放到不同的服务端,服务端用cook ...

  8. mysql & vs2013

    一 mysql 版本介绍 在mysql的官网http://dev.mysql.com/上,mysql 大致分为两个版本,即免费的社区版(community)和 付费的商业版(commercial).其 ...

  9. c# assembly

    string path = @"c:\text.dll" Assembly assembly = Assembly.LoadFile(path); path = "MyP ...

  10. 【前端学习笔记】call、apply、bind方法

    1.call()方法: // move函数实现移动平面图上一个点位置功能 var move = function(x,y){ this.x += x; this.y += y; } // 定一个点p ...