Road Optimization

The Government of Mars is not only interested in optimizing space flights, but also wants to improve the road system of the planet.

One of the most important highways of Mars connects Olymp City and Kstolop, the capital of Cydonia. In this problem, we only consider the way from Kstolop to Olymp City, but not the reverse path (i. e. the path from Olymp City to Kstolop).

The road from Kstolop to Olymp City is \ellℓ kilometers long. Each point of the road has a coordinate xx (0 \le x \le \ell0≤x≤ℓ), which is equal to the distance from Kstolop in kilometers. So, Kstolop is located in the point with coordinate 00, and Olymp City is located in the point with coordinate \ellℓ.

There are nn signs along the road, ii-th of which sets a speed limit a_iai​. This limit means that the next kilometer must be passed in a_iai​ minutes and is active until you encounter the next along the road. There is a road sign at the start of the road (i. e. in the point with coordinate 00), which sets the initial speed limit.

If you know the location of all the signs, it's not hard to calculate how much time it takes to drive from Kstolop to Olymp City. Consider an example:

Here, you need to drive the first three kilometers in five minutes each, then one kilometer in eight minutes, then four kilometers in three minutes each, and finally the last two kilometers must be passed in six minutes each. Total time is 3\cdot 5 + 1\cdot 8 + 4\cdot 3 + 2\cdot 6 = 473⋅5+1⋅8+4⋅3+2⋅6=47 minutes.

To optimize the road traffic, the Government of Mars decided to remove no more than kk road signs. It cannot remove the sign at the start of the road, otherwise, there will be no limit at the start. By removing these signs, the Government also wants to make the time needed to drive from Kstolop to Olymp City as small as possible.

The largest industrial enterprises are located in Cydonia, so it's the priority task to optimize the road traffic from Olymp City. So, the Government of Mars wants you to remove the signs in the way described above.

Input

The first line contains three integers nn, \ellℓ, kk (1 \le n \le 5001≤n≤500, 1 \le \ell \le 10^51≤ℓ≤105, 0 \le k \le n-10≤k≤n−1), the amount of signs on the road, the distance between the cities and the maximal number of signs you may remove.

The second line contains nn integers d_idi​ (d_1 = 0d1​=0, d_i < d_{i+1}di​<di+1​, 0 \le d_i \le \ell - 10≤di​≤ℓ−1) — coordinates of all signs.

The third line contains nn integers a_iai​ (1 \le a_i \le 10^41≤ai​≤104) — speed limits.

Output

Print a single integer — minimal possible time to drive from Kstolop to Olymp City in minutes, if you remove no more than kk road signs.

当时打cf比赛的时候就被他卡住了,放现在来看只要认真dp,找出状态转移方程,轻松拿下!

上代码!

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
int n,l,k,f[505][505],d[505],a[505];
int main(){
	cin>>n>>l>>k;
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=1;i<=n;i++)cin>>a[i];
	memset(f,0x3f,sizeof(f));
	d[++n]=l;f[1][0]=0;
	int ans=1e9;
	for(int i=2;i<=n;i++)
		for(int j=0;j<=k;j++){
			for(int p=1;p<i;p++)if(i-p-1<=j)f[i][j]=min(f[i][j],f[p][j-(i-p-1)]+a[p]*(d[i]-d[p]));
			if(i==n)ans=min(ans,f[i][j]);
		}cout<<ans;
	return 0;	
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值