Electric Bike

题目连接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4920

Description

Two years ago, Putri bought an electric bike (e-bike). She likes e-bike a lot since it can assist her in

cycling through steep roads when commuting to work. Over time, the battery capacity decreases. Now,

her e-bike battery capacity is so low that she needs to carefully plan when to turn on the assist and at

which level; different level of assist consumes different amount of energy and produces different assist

power.

Putri divides the road that she travels from her home to her workplace into N segments where each

segment has a steepness level. For example, the figure below shows a road with N = 7 segments.

Segment #1 #2 #3 #4 #5 #6 #7

Steepness 10 3 0 1 2 15 9

From her home, Putri has to travel from the first road segment, to the second road segment, and so on,

until the last segment to reach her work place. In the example above, the first segment has steepness of

10 which means Putri has to pedal her bike with 10 unit of energy. Her e-bike has fixed 4 assist levels

where each level generates different power, as shown in the following table:

Assist Level 0 1 2 3

Assist Power 0 4 8 11

Assist level L will consume L unit of energy from the battery and will give Putri additional pedaling

assist power according to the table above. Putri can only change the assist level to level L if the battery

has at least L energy left and she is at the beginning of a road segment. Setting an assist level where

the generated power is higher than the road steepness will cause the excess energy power to be wasted.

For example, if Putri sets the assist level L = 2 at the beginning of the first road segment (with

steepness 10), then she only needs to pedal her bike with 2 unit of energy instead of 10 (since her ebike

is assisting her with 8 unit of energy) to advance to the second road segment. If Putri sets the assist

level L = 3, her e-bike generates more power to handle the steepness 10, thus she does not need to

pedal at all, and the excess energy is wasted.

Putri can change the assist level instantly before entering a road segment, however, she does not

want to change the assist level more than K times (it’s too tiring). If there is not enough energy in

the battery to support the selected assist level for the road segment, the e-bike will shutdown at the

beginning of the road segment and Putri has to pedal through the rest of the road segments, i.e. the

assist level automatically set to 0 for the rest of the journey. Note that Putri can change her e-bike

assist level (given it’s still less than K) at the beginning of the road segment to avoid shutdown by

force. Initially at her home, the assist level is set to 0 and the battery is fully charged with E unit of

energy. Putri wants to know the minimum energy she will need to pedal the bike to reach the workplace

if she utilizes her e-bike optimally.

Input

The first line of input contains T (T ≤ 100) denoting the number of cases. Each case begins with three

integers: N, K, and E in a line (1 ≤ N ≤ 1, 000; 0 ≤ K ≤ 10; 0 ≤ E ≤ 50) as described in the problem

statement above. The next line contains N non-negative integers denoting the steepness level of i-th

segment where i = 1 . . . N respectively. The steepness level of any road segment is at most 15.

Output

For each case, output ‘Case #X: Y ’, where X is the case number starts from 1 and Y is the minimum

energy Putri needs to pedal the e-bike from her home to her workplace.

Explanation for 1st sample case:

Putri changes the assist level to 1 at (the beginning of) road segment #2, then change the assist

level to 3 at road segment #6. Thus, she needs to pedal with 10 unit of energy for road segment #1 and

4 unit of energy for road segment #6. Note that if she changes the assist level to 1 at road segment #1

and then to assist level 3 at road segment #6, then at the beginning of road segment #7 the battery

only has 2 unit of energy left and will automatically shutdown to assist level 0, thus Putri has to pedal

with 9 energy for road segment #7.

Explanation for 2nd sample case:

Putri changes the assist level to 3 at road segment #1 and then changes to assist level 2 at road

segment #2. Thus, she only needs to pedal 7 unit of energy for road segment #6 and 1 unit of energy

for road segment #7.

Explanation for 3rd sample case:

Putri changes the assist level to 3 at road segment #1, then changes to assist level 1 at road segment

2, finally changes to assist level 3 at road segment #6. Thus, she only needs to pedal 4 unit of energy

for road segment #6.

Sample Input

5

7 2 10

10 3 0 1 2 15 9

7 2 15

10 3 0 1 2 15 9

7 3 15

10 3 0 1 2 15 9

5 2 5

11 15 1 14 12

15 8 30

2 14 6 1 2 13 14 12 13 12 7 12 1 2 10

Sample Output

Case #1: 14

Case #2: 8

Case #3: 4

Case #4: 34

Case #5: 18

Hint

题意

有n个线段,每个线段长a[i]米,然后你骑着一个电瓶车,电瓶车只有E的电,然后一档需要1能量,可以帮你爬4米,2档需要2能量,可以帮你爬8米,3档需要3能量,可以帮你爬11米。

然后你不够的时候,就只能自己骑上去。

你最多修改k次档位。

如果你能量不够的话,那么你就强行退回了0档,且不能变成其他档。

题解:

虽然是个DP,但实际上是一个模拟题,特别烦……

你就把题目中所有的变量,都当成dp状态跑一边就行了。……

其实可能写成记忆化搜索的形式,更好一点。

代码

#include<bits/stdc++.h>
using namespace std;
int dp[1005][11][51][4][2];
int p[4]={0,4,8,11};
int a[1005];
int cas;
//第i个位置,j次换档,花了k,当前档为t
void solve(){
int n,k,e;
scanf("%d%d%d",&n,&k,&e);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=0;i<1005;i++)
for(int j=0;j<11;j++)
for(int k=0;k<51;k++)
for(int t=0;t<4;t++)
for(int i2=0;i2<2;i2++)
dp[i][j][k][t][i2]=1e9;
dp[0][0][0][0][0]=0;
dp[0][0][0][0][1]=0;
for(int i=0;i<n;i++){
for(int j=0;j<=k;j++){
for(int K=0;K<=e;K++){
for(int t=0;t<4;t++){
for(int m=0;m<4;m++){
dp[i+1][j][K][0][1]=min(dp[i+1][j][K][0][1],dp[i][j][K][t][0]+a[i+1]);
dp[i+1][j][K][0][1]=min(dp[i+1][j][K][0][1],dp[i][j][K][0][1]+a[i+1]);
if(t==m){
if(K+m>e)
dp[i+1][j][K][0][1]=min(dp[i+1][j][K][0][1],dp[i][j][K][t][0]+a[i+1]);
else
dp[i+1][j][K+m][m][0]=min(dp[i+1][j][K+m][m][0],dp[i][j][K][t][0]+max(0,a[i+1]-p[m]));
}else{
if(j==k){
continue;
}else if(K+m>e)
dp[i+1][j+1][K][0][1]=min(dp[i+1][j+1][K][0][1],dp[i][j][K][t][0]+a[i+1]);
else
dp[i+1][j+1][K+m][m][0]=min(dp[i+1][j+1][K+m][m][0],dp[i][j][K][t][0]+max(0,a[i+1]-p[m]));
}
}
}
}
}
}
int Ans = 1000000000;
for(int j=0;j<=k;j++)
for(int K=0;K<=e;K++)
for(int t=0;t<4;t++)
for(int i2=0;i2<2;i2++)
Ans=min(Ans,dp[n][j][K][t][i2]);
printf("Case #%d: %d\n",++cas,Ans);
}
int main(){
int t;
scanf("%d",&t);
while(t--)solve();
return 0;
}

UVALive 6908 Electric Bike dp的更多相关文章

  1. UVALive 6908---Electric Bike(DP或记录型深搜)

    题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  2. UVALive - 6952 Cent Savings dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/116998 Cent Savings Time Limit: 3000MS 问题描述 To host a re ...

  3. UVALive - 6529 找规律+dp

    题目链接: http://acm.hust.edu.cn/vjudge/problem/47664 Eleven Time Limit: 5000MS 问题描述 In this problem, we ...

  4. UVaLive 6801 Sequence (计数DP)

    题意:给定一个序列,有 n 个数,只有01,然后你进行k次操作,把所有的1变成0,求有多种方法. 析:DP是很明显的,dp[i][j] 表示进行第 i 次操作,剩下 j 个1,然后操作就两种,把1变成 ...

  5. UVaLive 6697 Homework Evaluation (DP)

    题意:给出一个长字符串,再给一个短字符串,进行匹配,如果第i个恰好匹配,则 +8,:如果不匹配,可以给长或短字符串添加-,先后匹配,这样-3, 连续的长字符串添加-,需要减去一个4:也可不给添加-,则 ...

  6. UVaLive 7374 Racing Gems (DP,LIS)

    题意:以辆赛车可以从x轴上任意点出发,他的水平速度允许他向每向上移动v个单位,就能向左或向右移动v/r个单位(也就是它的辐射范围是个等腰三角形) 现在赛车从x轴出发,问它在到达终点前能吃到的最多钻石. ...

  7. UVALive 6947 Improvements(DP+树状数组)

    [题目链接] https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=sho ...

  8. UVaLive 3490 Generator (KMP + DP + Gauss)

    题意:随机字母组成一个串,有一个目标串,当这个由随机字母组成的串出现目标串就停止,求这个随机字母组成串的期望长度. 析:由于只要包含目标串就可以停止,所以可以先把这个串进行处理,也就是KMP,然后dp ...

  9. UVALive 5983 二分答案+dp

    想了很久都想不出怎么dp,然后发现有些例子,如果你开始不确定起始值的话,是不能dp的,每种状态都有可能,所以只能二分一个答案,确定开始的val值,来dp了. #include <cstdio&g ...

随机推荐

  1. 官方资料&一些好的博客与技术点

    https://technet.microsoft.com/zh-cn/library/hh848794.aspxzh   https://msdn.microsoft.com/en-us/power ...

  2. Apache Oozie Coordinator 作业自定义配置定时任务

    一,介绍 Oozie是Hadoop的工作流系统,如果使用Oozie来提交MapReduce作业(Oozie 不仅仅支持MapReduce作业,还支持其他类型的作业),可以借助Oozie Coordin ...

  3. python-super1

    一.问题的发现与提出 一般子类在继承父类后,若子类覆盖了父类,则只执行子类,不执行父类.如果没有,则执行父类代码. 发现使用super()后,子类,父类都会执行,比较疑惑,记录学习,super知识点 ...

  4. 恶意代码分析实战-确认EXE什么时候编译的

    场景 确认开源的后门在中毒机器上是什么版本,具有什么功能. 思路 1.查看样本PE里的编译时间 2.对照开源后门里组件的编译时间 技术点 查看NT头-TimeDateStamp struct IMAG ...

  5. 两种常量类型-readonly和const

    C#中有两种常量类型,分别为readonly(运行时常量)与const(编译时常量),本文将就这两种类型的不同特性进行比较并说明各自的适用场景. 工作原理 readonly 为运行时常量(动态常量), ...

  6. free命令中的buffer和cached的比较(转)

    原文链接:https://www.jianshu.com/p/cd2dd59d1566 最近在搞监控,突然看到我系统的内存要用完了,赶紧登录服务器看看, ~]# dstat -m     16G内存就 ...

  7. KNN算法的感受 1

    本来预计的打算是一天一个十大挖掘算法,然而由于同时要兼顾数据结构面试的事情,所以 很难办到,但至少在回家前要把数据挖掘十大算法看完,过个好年,在course上学习老吴的课程还是帮了我很大的忙,虽然浪费 ...

  8. opencv 车牌字符分割 ANN网络识别字符

    最近在复习OPENCV的知识,学习caffe的深度神经网络,正好想起以前做过的车牌识别项目,可以拿出来研究下 以前的环境是VS2013和OpenCV2.4.9,感觉OpenCV2.4.9是个经典版本啊 ...

  9. 前后端分离之mockjs实战demo

    基于vue-cli+webpack的demo 项目结构 axios文件夹用来创建axios相关配置: import axios from 'axios' import vue from 'vue' a ...

  10. Linux学习笔记:sed删除、插入数据

    一.sed删除文件第一行 sed -i '1d' file.txt -- 删除第一行 sed -i 'nd' file.txt -- 删除第n行 sed -i '$d' file.txt -- 删除最 ...