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. Win10自动安装游戏/应用

    近日有一些网友反馈Win10会自动安装一些游戏/应用.用户没有打开应用商店并且没有被要求获取批准,系统自动在系统中安装了一些应用. 比如有这样一位网友反馈了该问题,他在自己的系统中使用命令卸载了所有的 ...

  2. POJ 3260 The Fewest Coins 最少硬币个数(完全背包+多重背包,混合型)

    题意:FJ身上有各种硬币,但是要买m元的东西,想用最少的硬币个数去买,且找回的硬币数量也是最少(老板会按照最少的量自动找钱),即掏出的硬币和收到的硬币个数最少. 思路:老板会自动找钱,且按最少的找,硬 ...

  3. UWP开发:自动生成迷宫&自动寻路算法(1)

    (1)前端篇 首先,我们创建一个新的Universal Windows Platform程序.这些小方块是通过GridView来罗列的,这样可以避免MainPaga.xaml的<Rectangl ...

  4. 2002-2003 ACM-ICPC Northeastern European Regional Contest (NEERC 02) A Amusing Numbers (数学)

    其实挺简单的.先直接算出之前已经排在k这个数前面的数字.比如543是三位的,那么100~543都是可以的,两位的10~54. 如果还需要往前面补的话,那么依次考虑1000~5430,5430是上界不能 ...

  5. cdoj 414 八数码 (双向bfs+康拓展开,A*)

    一道关乎人生完整的问题. DBFS的优越:避免了结点膨胀太多. 假设一个状态结点可以扩展m个子结点,为了简单起见,假设每个结点的扩展都是相互独立的. 分析:起始状态结点数为1,每加深一层,结点数An ...

  6. [学习笔记]Linux下mysql的基础操作

    命令 #查看版本 mysql --version   #进入mysql 命令 mysql -u root -p mysql -u root@localhost (没有密码的情况)   #创建数据库 c ...

  7. windbg双机调试配置

    环境 虚拟机 win7 Pro x86 vmware 12 windbg x86 虚拟机win7配置 管理员权限运行cmd.exe 然后输入以下命令: bcdedit /? bcdedit /enum ...

  8. python报错UnicodeDecodeError:

    Python 里面的编码和解码也就是 unicode 和 str 这两种形式的相互转化.编码是 unicode -> str,相反的,解码就 是 str -> unicode.剩下的问题就 ...

  9. 01_12_Struts2_访问Web元素

    01_12_Struts2_访问Web元素 1. 配置struts.xml文件 <package name="login" namespace="/login&qu ...

  10. C++实现Singleton模式(effective c++ 04)

    阅读effective c++ 04 (31页) 提到的singleton设计模式.了解一下. 定义: 保证一个类仅有一个实例,并提供一个访问它的全局访问点,该实例被所有程序模块共享. 应用场景: 比 ...