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. Log4Net的使用研究(一)

    等待研究中………… 20160421 标题:C#使用Log4Net记录日志   文章地址: http://www.cnblogs.com/wangsaiming/archive/2013/01/11/ ...

  2. MySQL 事务 转自菜鸟教程 讲的清晰

    MySQL 事务 MySQL 事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数 ...

  3. Ubuntu 16.04 LTS安装sogou输入法详解

    http://blog.csdn.net/qq_21792169/article/details/53152700 最近开始学习linux 在安装输入法中遇到的一些问题,最终成功安装,也得益于网络上的 ...

  4. Java知识点整理(一)

    ArrayList和LinkedList的区别 1.ArrayList和LinkedList可想从名字分析,它们一个是Array(动态数组)的数据结构,一个是Link(链表)的数据结构,此外,它们两个 ...

  5. postman 上一个接口返回值传给下一个接口

    问题:如何将A请求responseBody中的token传入B请求中的request中 把A请求中的token设置为环境变量,如下: tests["Status code is 200&qu ...

  6. UVALive - 4975_Casting Spells

    题意很简单,给你一个字符串,要求你求出一个最长的形似于w(wr)w(wr)的最长连续子串的长度.wr表示w的逆序串. 在这里大家很容易就能想到Manacher算法求回文串.没有错,就是这个. 算法的详 ...

  7. Solr实现SQL的查询与统计--转载

    原文地址:http://shiyanjun.cn/archives/78.html Cloudera公司已经推出了基于Hadoop平台的查询统计分析工具Impala,只要熟悉SQL,就可以熟练地使用I ...

  8. 51nod 1674 区间的价值V2(思维+拆位+尺取法)

    最近被四区题暴虐... 题意:lyk拥有一个区间. 它规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有数or起来的值的乘积. 例如3个数2,3,6.它们and起来的值为2,or起来的值 ...

  9. BZOJ 2109 航空管制(拓扑排序+贪心)

    绝世好题啊.. 题意:给出一个DAG,和每个点要求出现在这个DAG里面的拓扑排序的位置<=ti,求出所有可能的拓扑排序里面每个点出现的位置的最小值. 正着做不好做,考虑反着做,建立这个图的反图. ...

  10. Android四大组件之Intent(续2)

    1.你如何通过一个intent来唤醒activity? this.startActivity(intent,request);      2.什么是显式.隐式的intents? 显式:指定组件名,通常 ...