当前位置: 代码迷 >> 综合 >> 百练OJ-Railway tickets
  详细解决方案

百练OJ-Railway tickets

热度:96   发布时间:2023-09-18 19:06:24.0
#include<iostream>//动态规划
using namespace std;
#define INF 0x3f3f3f3f
int main()
{int L1, L2, L3, C1, C2, C3;//cin >> L1 >> L2 >> L3 >> C1 >> C2 >> C3;scanf("%d%d%d%d%d%d", &L1, &L2, &L3, &C1, &C2, &C3);int N;cin >> N;int a, b;cin >> a;cin >> b;if (a > b) {int temp = a;a = b;b = temp;}int sta[10000];int dp[10000];for (int i = 2; i < N + 1; i++) {cin >> sta[i];}for (int i = a; i < b + 1; i++) {dp[i] = INF;}dp[a] = 0;for (int i = a; i < b; i++) {for (int j = i + 1; j < b + 1; j++) {if (sta[j] - sta[i] <= L1&&dp[j] > dp[i] + C1) {dp[j] = dp[i] + C1;}if (sta[j] - sta[i] <= L2&&dp[j] > dp[i] + C2) {dp[j] = dp[i] + C2;}if (sta[j] - sta[i] <= L3&&dp[j] > dp[i] + C3) {dp[j] = dp[i] + C3;}}}cout << dp[b] << endl;return 0;
}