有坑!!!! timus 1031. Railway Tickets URAL 解题报告
来源:互联网 发布:家用电脑做数据服务器 编辑:程序博客网 时间:2024/05/29 03:53
timus 1031. Railway Tickets URAL 解题报告
题目大意,在一条铁轨上有一些站点,然后票价有是那种收费方式根据距离,超出最大距离的那么就能能中转,不能直达,问从s到e最少花费!
很明显的DP,当时就想,这个题如果有难点,可能会出现在超时或者高精度上,但是没想到,s,e没规定谁大谁小啊! 一直以为不会有这种类型的坑,今天算是见识了! 为什么把s,e直接交换就可以呢? 因为路径可以看做双向的,能去就能回来,按照取得方式倒回来就好!
状态转移,dp[i]表示从s到i最小花费,dp[i]=min(dp[i],dp[j]+c) j<i但是j>=e注意j的上下界!其他的地方都好说!
雄心铁胆打天下,拼搏生命笑对天。
大肚能容天下辱,站稳脚跟学做人!
#include <iostream>#include<cstdio>#include<cstring>using namespace std;#define MAXN 10010const int INF=0x7fffffff-1;typedef long long ll;ll dp[MAXN];int L1,L2,L3,c1,c2,c3;int n,s,e;ll dis[MAXN];int main(){///1031 while(scanf("%d%d%d%d%d%d",&L1,&L2,&L3,&c1,&c2,&c3)!=EOF) { //memset(dp,-1,sizeof(dp)); memset(dis,0,sizeof(dis)); /// cout<<dp[2]<<endl; scanf("%d%d%d",&n,&s,&e); for(int i=2;i<=n;++i) { scanf("%d",&dis[i]); } ///终于知道URAL也有坑了,s,e没规定谁大谁小啊 int da=max(s,e); int xiao=min(s,e); s=xiao;e=da; for(int i=s;i<=e;++i) { dp[i]=INF; } dp[s]=0;///临界状态,边界条件 for(int i=s+1;i<=e;++i) { for(int j=i-1;j>=s;--j) {///注意j的上下界 if(dis[i]-dis[j]>L3)break; if(dis[i]-dis[j]<=L1) {if(dp[i]==-1)dp[i]=dp[j]+c1; else dp[i]=min(dp[i],dp[j]+c1); }else if(dis[i]-dis[j]<=L2) { if(dp[i]==-1)dp[i]=dp[j]+c2; else dp[i]=min(dp[i],dp[j]+c2); }else if(dis[i]-dis[j]<=L3) { if(dp[i]==-1)dp[i]=dp[j]+c3; else dp[i]=min(dp[i],dp[j]+c3); } } } cout <<dp[e]<< endl; } return 0;}
1031. Railway Tickets
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
The railway line “Yekaterinburg-Sverdlovsk” with several stations has been built. This railway line can be represented as a line segment, railway stations being points on it. The railway line starts at the station “Yekaterinburg” and finishes at the station “Sverdlovsk”, so stations are numbered starting from “Yekaterinburg” (it has number 1) and “Sverdlovsk” is the last station.
Cost of the ticket between any two stations depends only on a distance between them. The prices for the tickets are specified in the following table.
Direct tickets from one station to another can be booked if and only if the distance between these station does not exceed L3. So sometimes it is necessary to book several tickets to pay for the parts of the whole way between stations.
For example, on the railway line shown at the figure above there are seven stations. The direct ticket from the second station to the sixth one can not be booked. There are several ways to pay for the travel between these stations. One of them is to book two tickets: one ticket at price C2 to travel between the second and the third stations, and other at price C3 to travel between the third and the sixth stations. Note, that though the distance between the second and the sixth stations is equal to 2L2, the whole travel can not be paid by booking two tickets at price C2, because each ticket is valid for only one travel and each travel should start and end only at stations.
Your task is to write a program, that will find the minimal cost of the travel between two given stations.
Input
The first line of the input contains 6 integers L1, L2, L3, C1, C2, C3 (1 ≤ L1 < L2 < L3 ≤ 109, 1 ≤ C1 < C2 < C3 ≤ 109) in the specified order with one space between. The second line contains the amount of stations N (2 ≤ N ≤ 10000). The third line contains two different integers separated by space. They represent serial numbers of stations, the travel between which must be paid. Next N−1 lines contain distances from the first station (“Yekaterinburg”) on the railway line to others. These distances are given as different positive integers and are arranged in the ascending order. The distance from “Yekaterinburg” to “Sverdlovsk” does not exceed 109. The distance between any neighboring stations does not exceed L3. The minimal travel cost between two given stations will not exceed 109.
Output
Program should print to the output the only number, which is the minimal travel cost between two given stations.
Sample
3 6 8 20 30 4072 6378131523
70
timus 1031. Railway Tickets URAL 解题报告
- 有坑!!!! timus 1031. Railway Tickets URAL 解题报告
- timus 1036. Lucky Tickets URAL 解题报告
- Timus 1031. Railway Tickets
- Ural 1031. Railway tickets
- ural 1031. Railway Tickets | poj 2355
- 1031. Railway Tickets(URAL 1031 )
- ural 1031 Railway Tickets
- timus 1167. Bicolored Horses URAL 解题报告
- timus 1029. Ministry URAL 解题报告
- timus 1287. Mars Canals URAL 解题报告
- timus 1513. Lemon Tale URAL 解题报告
- timus 1244. Gentlemen URAL 解题报告
- timus 1319. Hotel URAL 解题报告
- timus 1149. Sinus Dances URAL 解题报告
- timus 1640. Circle of Winter URAL 解题报告 水题一枚,坑死多少英雄啊……
- timus 1353. Milliard Vasya's Function 解题报告 URAL
- timus 1260. Nudnik Photographer 解题报告 URAL 找规律?DP
- DP+路径回溯 timus 1078. Segments URAL 解题报告
- CF 256E Lucky Arrarys 【线段树+DP】
- LINQ To XML:根据一个XML覆盖另一个XML节点内容
- svn第一篇----入门指南
- 东软实习报告
- 逻辑学学习:第一章:导论
- 有坑!!!! timus 1031. Railway Tickets URAL 解题报告
- 对.net系统架构改造的一点经验和教训
- Linux内核源码阅读之打开文件篇
- struts2前端页面控件值的加号变空格的解决方法
- 将php数组中的键名删除,但是保留键值
- openssl安装及使用
- 成人网站YouPorn使用Redis 之经验谈
- 从键盘多行输入,写入TXT文件并读取输出~只显示第一行,如何解决?(答案见代码)
- mysql相关知识