递推DP URAL 1031 Railway Tickets

时间:2022-05-25 01:13:25

题目传送门

 /*
简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF
注意:s1与s2大小不一定,坑!
详细解释:http://blog.csdn.net/kk303/article/details/6847948
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
using namespace std; const int MAXN = 1e4 + ;
const int INF = 0x3f3f3f3f;
int C[], L[];
int dp[MAXN], a[MAXN]; int main(void) //URAL 1031 Railway Tickets
{
//freopen ("Y.in", "r", stdin); while (scanf ("%d%d%d%d%d%d", &L[], &L[], &L[], &C[], &C[], &C[]) == )
{
int n; scanf ("%d", &n);
int s1, s2;
scanf ("%d%d", &s1, &s2);
if (s1 > s2) swap (s1, s2);
a[] = ;
for (int i=; i<=n; ++i)
{
scanf ("%d", &a[i]); dp[i] = INF;
} dp[s1] = ;
for (int i=s1+; i<=s2; ++i)
{
for (int j=; j<=; ++j)
{
int k = i - ;
while (k >= s1)
{
if (a[i] - a[k] > L[j]) break;
if (dp[i] > dp[k] + C[j]) dp[i] = dp[k] + C[j];
k--;
}
}
} printf ("%d\n", dp[s2]);
} return ;
}