CF760 D Travel Card 简单DP
题意:乘车,有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的更多相关文章
- 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 ...
- 【二分】【动态规划】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 ...
- Travel Card
Travel Card time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- 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 ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
随机推荐
- Alpha 冲刺(7/10)
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 学习MSI.CUDA 试运行软件并调试 ...
- Python安装Numpy,matplotlib库
<1> Numpy是一款基于python的功能强大的科学计算包.要安装numpy首先你得先安装python. python的安装非常简单,本人安装的是python2.7 具体安装步骤如下: ...
- 一些有趣的erlang项目
这里会收集一些erlang项目,有需可以转. erlang-bookmarks Scaling Erlang High Performance Erlang - Finding Bottlenecks ...
- 服务器BMC(带外)
服务器除了装linux,windows系统外,相应还有一个可通过网线(服务器默认带外地址--可改)连接具体厂商服务器的BMC(Baseboard Management Controller,基板管理控 ...
- jQuery的滚动监听
jQuery的滚动监听 1.当前滚动的地方的窗口顶端到整个页面顶端的距离: var winPos = $(window).scrollTop(); 2.获取指定元素的页面位置: $(val).offs ...
- MySQL 事务 转自菜鸟教程 讲的清晰
MySQL 事务 MySQL 事务主要用于处理操作量大,复杂度高的数据.比如说,在人员管理系统中,你删除一个人员,你即需要删除人员的基本资料,也要删除和该人员相关的信息,如信箱,文章等等,这样,这些数 ...
- Windows连接Linux服务器中MySQL数据库-权限配置
问题描述 在Windows系统中安装了监控MySQL数据库服务器性能的工具Spotlight on MySQL,利用Spotlight连接Linux服务器中的MySQL,进行相关配置如下: 点击& ...
- win8平板APP开发的教程文章
http://blog.csdn.net/tcjiaan/article/details/7866595 基于C#的Metro工程如何引用C++的动态库——FIleNotFound解决办法: http ...
- PHP中与类有关的运算符
与类有关的运算符: new, instanceof:判断一个“变量”(对象,数据),是否是某个类的“实例”: 示意如下: class A {} class B {} class C extend ...
- POJ3378_Crazy Thairs
这个题目很有意思,也是一个很好的题目,涉及的知识点比较广,要求较高. 题目是这样的,给定你一个n个数的数列,问你有多少个长度为5的上升序列. 首先看到有50000,我们就知道肯定不会是DP.(但是不知 ...