AtCoder Regular Contest 067--D - Walk and Teleport--贪心

D - Walk and Teleport Time Limit: 2 sec / Memory Limit: 256 MB Score : points Problem Statement There are towns on a line running east-west. The towns are numbered through , in order from west to east. Each point on the line has a onedimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of town is . You are now at town , and you want to visit all the other towns. You have two ways to travel: Walk on the line. Your fatigue level increases by each time you travel a distance of , regardless of direction. Teleport to any location of your choice. Your fatigue level increases by , regardless of the distance covered. Find the minimum possible total increase of your fatigue level when you visit all the towns in these two ways. Constraints All input values are integers. For all , . Input The input is given from Standard Input in the following format: Output Print the minimum possible total increase of your fatigue level when you visit all the towns. Sample Input 1 4 2 5 1 2 5 7 Sample Output 1 11 From town , walk a distance of to town , then teleport to town , then walk a distance of to town . The total increase of your fatigue level in this case is , which is the minimum possible value. Sample Input 2 7 1 100 40 43 45 105 108 115 124 Sample Output 2 84 From town , walk all the way to town . The total increase of your fatigue level in this case is , which is the minimum possible value. Sample Input 3 500 N 1 N i Xi 1 A 1 B 2 ≤ N ≤ 10 5 1 ≤ Xi ≤ 10 9 i(1 ≤ i ≤ N − 1) Xi < Xi+1 1 ≤ A ≤ 10 9 1 ≤ B ≤ 10 9 N A B X1 X2 . . . XN 1 1 2 3 2 4 2 × 1 + 5 + 2 × 2 = 11 1 7 84 2019/5/27 AtCoder Regular Contest 067 https://atcoder.jp/contests/arc067/tasks_print 3/5 Sample Input 3 7 1 2 24 35 40 68 72 99 103 Sample Output 3 12 Visit all the towns in any order by teleporting six times. The total increase of your fatigue level in this case is 12, which is the minimum possible value

 

//每一步选择最小值就行啦

注意初始化的时候DP[0]=0 

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int maxn=1e5+10;
ll num[maxn];
ll dp[maxn];
int main()
{
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&num[i]);
       // dp[i]=num[i]*a;
    }
    dp[1]=0;//在第一步为0
    for(int i=2; i<=n; i++)
    {
        //每次走一步需要A
        //任意走需要B
        //每一步取得最小值
        dp[i]=min(dp[i-1]+(num[i]-num[i-1])*a,dp[i-1]+b);
    }
    printf("%lld\n",dp[n]);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值