codeforces534B
Covered Path
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals v1 meters per second, and in the end it is v2meters per second. We know that this section of the route took exactly t seconds to pass.
Assuming that at each of the seconds the speed is constant, and between seconds the speed can change at most by d meters per second in absolute value (i.e., the difference in the speed of any two adjacent seconds does not exceed d in absolute value), find the maximum possible length of the path section in meters.
Input
The first line contains two integers v1 and v2 (1 ≤ v1, v2 ≤ 100) — the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers t (2 ≤ t ≤ 100) — the time when the car moves along the segment in seconds, d (0 ≤ d ≤ 10) — the maximum value of the speed change between adjacent seconds.
It is guaranteed that there is a way to complete the segment so that:
- the speed in the first second equals v1,
- the speed in the last second equals v2,
- the absolute value of difference of speeds between any two adjacent seconds doesn't exceed d.
Output
Print the maximum possible length of the path segment in meters.
Examples
5 6
4 2
26
10 10
10 0
100
Note
In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5 + 7 + 8 + 6 = 26 meters.
In the second sample, as d = 0, the car covers the whole segment at constant speed v = 10. In t = 10 seconds it covers the distance of 100 meters.
sol:一开始以为是小学奥数一样的东西,写了一堆特判后发现根本讨论不完,于是彻底自闭
发现是个很裸的dp,dp[i][j]表示第 i 秒,速度为 j 的最大路程
Ps:初速度100,加速度10,加速时间100,要开1105的数组,唯一的坑点
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int v1,v2,t,d,dp[][N];
int main()
{
int i,j,k;
R(v1); R(v2); R(t); R(d);
memset(dp,-,sizeof dp);
dp[][v1]=v1;
for(i=;i<t;i++)
{
for(j=;j<=i*d+v1;j++) if(dp[i][j]!=-)
{
for(k=-d;k<=d;k++)
{
if(j+k>=) dp[i+][j+k]=max(dp[i+][j+k],dp[i][j]+j+k);
}
}
}
// for(i=1;i<=t;i++)
// {
// for(j=0;j<=v2;j++) printf("%d ",dp[i][j]); puts("");
// }
Wl(dp[t][v2]);
return ;
}
/*
Input
5 6
4 2
Output
26 Input
10 10
10 0
Output
100 Input
87 87
2 10
Output
174 Input
1 11
6 2
Output
36 Input
100 1
100 10
Output
29305 input
100 1
100 1
output
5050
*/
codeforces534B的更多相关文章
随机推荐
- BZOJ1390 CEOI2008 Fences 凸包、Floyd最小环/DP
传送门 为了方便描述把固定点叫做白色点,Tree叫做黑色点 一种基于特殊性质的做法: 如果不算入选白色的权值,那么一定会选中所有白色点构成的凸包上的点,因为能够尽可能围更多的黑色点.然后我们在这个基础 ...
- GitHub Or Subversion
上一次转载了介绍GitHub的博文点我,我想对于初学GitHub的同学们还是有不清楚的地方,毕竟有些概念的理解比较费力.我觉得作为一个对于配置库技术已经有一定基础的同学们,要学习GitHub,最快以及 ...
- .NET开源项目 QuarkDoc 一款自带极简主义属性的文档管理系统
有些话说在前头 因为公司产品业务重构且功能拆分组件化,往后会有很多的接口文档需要留存,所以急需一款文档管理系统.当时选型要求3点: 1.不能是云平台上的Saas服务,整个系统都要在自己公司部署维护(数 ...
- virtualenv虚拟环境的使用
前提条件:安装好python环境并配置好环境变量(可参考另一篇博文,python安装及配置) 1.打开cmd命令终端 pip3 install virtualenvwrapper-win(我电脑上面已 ...
- nginx 之 proxy_redirect详解
proxy_redirect 语法:proxy_redirect [ default|off|redirect replacement ] 默认值:proxy_redirect default 使 ...
- H5 CSS的格式
02-CSS的格式 标签名称{ 属性名称: 属性对应的值; ... } 2.注意点: 1.style标签必须写在head标签的开始标签和结束标签之间(也就是必须和title标签是兄弟关系) 2.sty ...
- ASP.NET项目开发
ASP.NET项目开发 1.C/S模式 (client 客户端 server 服务器):QQ.证券.酷狗.旺旺...需要下载响应软件: 工作原理:客户端请求--ASP.net服务器端应用(<-- ...
- Vue $nextTick 原理
使用场景 在进行获取数据后,需要对新视图进行下一步操作或者其他操作时,发现获取不到 DOM. 原因: 这里就涉及到 Vue 一个很重要的概念:异步更新队列(JS运行机制 . 事件循环). Vue 在观 ...
- R语言
什么是R语言编程? R语言是一种用于统计分析和为此目的创建图形的编程语言.不是数据类型,它具有用于计算的数据对象.它用于数据挖掘,回归分析,概率估计等领域,使用其中可用的许多软件包. R语言中的不同数 ...
- Springboot+Redis 配置和使用
pom.xml 引入redis 开启缓存 <!-- cache --> <dependency> <groupId>org.springframework.boot ...