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的更多相关文章
随机推荐
- bernoulli数
LL B[N][],C[N][N],f[N][]; int n,m; LL gcd(LL a,LL b){return b?gcd(b,a%b):a;} LL lcm(LL a,LL b){retur ...
- linux日志:syslogd和klogd及syslog
一. 日志守护进程 syslogd和klogd是很有意思的守护进程,syslogd是一个分发器,它将接收到的所有日志按照/etc/syslog.conf的配置策略发送到这些日志应该去的地方,当然也包括 ...
- 极其好用好学的规则引擎 - A2D规则引擎
写了个简单的规则引擎,普通情况够用了: 比如2家公司有各自的利率计算规则,如下: 在C#方面,没有写在C#的业务逻辑代码中,而是移到了外部规则文件中,如(ACompanyRatePolicy.r): ...
- 语法设计——基于LL(1)文法的预测分析表法
实验二.语法设计--基于LL(1)文法的预测分析表法 一.实验目的 通过实验教学,加深学生对所学的关于编译的理论知识的理解,增强学生对所学知识的综合应用能力,并通过实践达到对所学的知识进行验证.通过对 ...
- H5 26-CSS三大特性之优先级
26-CSS三大特性之优先级 类>标签>通配符>继承>浏览器默认 --> 0 我是段落 <!DOCTYPE html> <html lang=" ...
- 有界算子p129
? 如果我把这里的1改成2,把1/(a-b) 换成1/2(a-b) 为什么不能是? 2. 这里的x是关于t的函数,为什么x属于 结果了?和x应该没有关系呀? 3. 那为什么T的范数不是一个固定值?为什 ...
- HTTPS建立连接的过程
HTTP建立连接的过程点击:HTTP三次握手.一次HTTP请求都发生了什么 一.HTTPS HTTP是超文本传输协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私 ...
- [2017BUAA软工助教]第0次作业小结
BUAA软工第0次作业小结 零.题目 作业链接: This is a hyperlink 一.评分规则 本次作业满分10分: 按时提交有分 一周内补交得0分 超过一周不交或抄袭倒扣全部分数 评分规则如 ...
- 将iso镜像转换为docker镜像
为什么不用官方的镜像? 不是不想使用,而是官方镜像提供的功能实在是太少了,不信的话,你pull一个ubuntu:latest的进行,你看有没有wget.curl.ssh这些功能,就连最简单的ifcon ...
- Linux awk使用方法~~整理
目录 awk行处理方式 awk命令格式 命令行格式 脚本格式 命令行格式——基本格式 awk内置变量 awk内置函数 测试数据 awk变量和函数使用实例 逻辑判断式 扩展格式 BEGIN 和 END ...