Railway tickets
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2472   Accepted: 865

Description

The railway line "Ekaterinburg-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 "Ekaterinburg" and finishes at the station "Sverdlovsk", so stations are numbered starting from "Ekaterinburg" (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.

distance between stations -X

price for the ticket

0<X<=L1

C1

L1<X<=L2

C2

L2<X<=L3

C3

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 2*L2, 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 file contains 6 integers L1, L2, L3, C1, C2, C3 (1 <= L1 < L2 < L3 <= 10^9, 1 <= C1 < C2 < C3 <= 10^9) 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 ("Ekaterinburg") on the railway line to others. These distances are given as different positive integers and are arranged in the ascending order. The distance from "Ekaterinburg" to "Sverdlovsk" does not exceed 10^9. The distance between any neighboring stations does not exceed L3. The minimal travel cost between two given stations will not exceed 10^9.

Output

Program should print to the output file the only number, which is the minimal travel cost between two given stations.

Sample Input

3 6 8 20 30 40
7
2 6
3
7
8
13
15
23

Sample Output

70
题目大意:有一个铁路线,线上有n个站,每个站之间都有一段距离,这个车站根据路程的长短出售3种票,每种票能够乘坐的距离不同,一个票只能用于从一个站到另一个站,问从站a到站b花费的最少金钱。
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int dist[], dp[]; int main()
{
int L1, L2, L3, C1, C2, C3;
int n, s, e;
scanf("%d%d%d%d%d%d", &L1, &L2, &L3, &C1, &C2, &C3);
scanf("%d", &n);
scanf("%d%d", &s, &e);
if (s > e)
{
s ^= e;
e ^= s;
s ^= e;
}
for (int i = s; i <= e; i++)
{
dp[i] = 0x7fffffff;
}
dist[] = ;
for (int i = ; i <= n; i++)
{
scanf("%d", &dist[i]);
}
dp[s] = ;
for (int i = s; i < e; i++)
{
for (int j = i + ; j <= e; j++)
{
if (dist[j] - dist[i] <= L1 && dp[j] > dp[i] + C1)
{
dp[j] = dp[i] + C1;
}
if (dist[j] - dist[i] <= L2 && dp[j] > dp[i] + C2)
{
dp[j] = dp[i] + C2;
}
if (dist[j] - dist[i] <= L3 && dp[j] > dp[i] + C3)
{
dp[j] = dp[i] + C3;
}
}
}
printf("%d\n", dp[e]);
return ;
}
 

POJ 2355 Railway tickets的更多相关文章

  1. poj 2828 Buy Tickets (线段树(排队插入后输出序列))

    http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissio ...

  2. poj 2828 Buy Tickets 树状数组

    Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so ...

  3. poj 2828 Buy Tickets (线段树 单节点 查询位置更新)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 15533   Accepted: 7759 Desc ...

  4. POJ 2828 Buy Tickets(线段树 树状数组/单点更新)

    题目链接: 传送门 Buy Tickets Time Limit: 4000MS     Memory Limit: 65536K Description Railway tickets were d ...

  5. POJ 2828 Buy Tickets

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

  6. poj 2828 Buy Tickets【线段树单点更新】【逆序输入】

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16273   Accepted: 8098 Desc ...

  7. 线段树(倒序操作):POJ 2828 Buy Tickets

    Buy Tickets   Description Railway tickets were difficult to buy around the Lunar New Year in China, ...

  8. POJ 2828 Buy Tickets(排队问题,线段树应用)

    POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意:  排队买票时候插队.  给出一些数对,分别代表某个人的想要插入的位 ...

  9. POJ - 2828 Buy Tickets (段树单点更新)

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

随机推荐

  1. Jquery 事件 DOM操作

    常规事件: 把JS的事件  on去掉即可 例如:js    document.getElementById("id").onclinck=function(){} Jquery   ...

  2. redmine安装详解

    1.Linux:centos6.4(32位)2.Gcc的编译环境.使用make命令编辑.yum install gcc-c++ 3.PCRE PCRE(Perl Compatible Regular ...

  3. HDU - 5493 Queue 2015 ACM/ICPC Asia Regional Hefei Online(线段树)

    按身高排序,每个人前面最高的人数有上限,如果超出上限说明impossible, 每次考虑最小的人,把他放在在当前的从左往右第k+1个空位 因为要求字典序最小,所以每次k和(上限-k)取min值. 没有 ...

  4. python_91_正则表达式

    常用的正则表达式: '.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r& ...

  5. SD Card Formatter for Mac Download

    https://www.sdcard.org/downloads/formatter_4/eula_mac/ SDFormatter Mac版是一款Mac OS平台上的sd卡修复工具,SDFormat ...

  6. 面向对象OONo.3单元总结

    一,JML语言 1)JML理论基础:JML是一类语言,用来描述一个方法或一个类的功能.以及这个类在实现这个功能时需要的条件.可能改变的全局变量.以及由于条件问题不能实现功能时这个方法或类的行为,具有明 ...

  7. Java删除开头和末尾字符串

    //扩展2个String方法 /* * 删除开头字符串 */ public static String trimstart(String inStr, String prefix) { if (inS ...

  8. java基础—super关键字

    一.super关键字

  9. linux下libnet编程 亲自测试可用

    linux下libnet编程 亲自测试可用 亲自测试  如果build包的时候 只要把类型改了 就能改成相应的协议. 0x0800 ip 0x0806 arp 0x86DD    IPv6 0x86e ...

  10. NSOperation、NSOperationQueue

    NSOperation.NSOperationQueue NSOperation 和 NSOperationQueue 配合使用也能实现多线程. NSOperation 继承于 NSObject,是一 ...