Codeforces 855B - Marvolo Gaunt's Ring
思路:①枚举a[j],a[i]和a[k]分别用前缀最小值最大值和后缀最小值和后缀最大值确定。
②dp,dp[i][j]表示到第j为止,前i+1个值加起来的最大值。
代码:
代码①:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+;
const int INF=0x3f3f3f3f; int a[N];
int premx[N];
int premn[N];
int sufmx[N];
int sufmn[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll n,p,q,r;
cin>>n>>p>>q>>r;
for(int i=;i<=n;i++)cin>>a[i];
premx[]=-INF,premn[]=INF;
for(int i=;i<=n;i++)premx[i]=max(premx[i-],a[i]),premn[i]=min(premn[i-],a[i]);
sufmx[n+]=-INF,sufmn[n+]=INF;
for(int i=n;i>=;i--)sufmx[i]=max(sufmx[i+],a[i]),sufmn[i]=min(sufmn[i+],a[i]); ll ans=-;
for(int i=;i<=n;i++)ans=max(ans,max(p*premx[i],p*premn[i])+q*a[i]+max(r*sufmx[i],r*sufmn[i]));
cout<<ans<<endl;
return ;
}
代码②:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int N=1e5+;
const ll _INF=-8e18;
ll dp[][N];
int a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie();
ll p,q,r,n;
cin>>n>>p>>q>>r;
for(int i=;i<=n;i++)cin>>a[i]; dp[][]=_INF;
dp[][]=_INF;
dp[][]=_INF;
for(int i=;i<=n;i++)
{
dp[][i]=max(dp[][i-],p*a[i]);
dp[][i]=max(dp[][i-],dp[][i]+q*a[i]);
dp[][i]=max(dp[][i-],dp[][i]+r*a[i]);
}
cout<<dp[][n]<<endl;
return ;
}
Codeforces 855B - Marvolo Gaunt's Ring的更多相关文章
- Codeforces 855B:Marvolo Gaunt's Ring(枚举,前后缀)
B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaun ...
- Marvolo Gaunt's Ring(巧妙利用前后缀进行模拟)
Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as h ...
- B. Marvolo Gaunt's Ring 前缀后缀
B. Marvolo Gaunt's Ring 这种一般只有三个的都可以处理前缀和后缀,再枚举中间这个值. 这个和之前写过的C. Four Segments 前缀后缀 处理方式很像. #include ...
- 【ST】【CF855B】 Marvolo Gaunt's Ring
传送门 Description 给定三个数 \(p~,~q~,~r~\),以及一个数组 \(a\), 找出三个数 \(i~,~j~,~k\) ,其中 \(i~\leq~j~\leq~k\) 最大化 \ ...
- 【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring
[链接]h在这里写链接 [题意] 给你n个数字; 让你在其中找出三个数字i,j,k(i<=j<=k); 使得p*a[i]+q*a[j]+r*a[k]最大; [题解] /* 有一个要 ...
- CodeForces - 855B ring 前缀和
邓布利多教授正在帮助哈利摧毁魂器.当他怀疑一个魂器出现在那里时,他去了冈特沙克.他看到Marvolo Gaunt的戒指,并将其确定为魂器.虽然他摧毁了它,但仍然受到诅咒的影响.斯内普教授正在帮助邓布利 ...
- codeforce 855B
B. Marvolo Gaunt's Ring time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Manthan, Codefest 17
A. Tom Riddle's Diary time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Harry Potter
Names appearing in "Harry Potter" 1.Harry Potter ①Harry is from Henry. ②Harry is related t ...
随机推荐
- Ants-穷举算法
package java操作excel; import java.util.Scanner; /** * Ants * n只蚂蚁以每秒1cm的速度在长为Lcm的竿子上爬行,当蚂蚁爬到端点就会掉下去,竿 ...
- lnmp之nginx1.10.2安装
linux下nginx的安装 为了后面避免缺失,还是什么都安装一下(后面安装php和mysql就不需要重复再执行下面这个了,当然你再执行一遍也没问题) [root@localhost src]# yu ...
- python , 顺序迭代合并后的list对象
有一系列排序序列,想将它们合并后得到一个排序序列并在上面迭代遍历 heapq.merge() 函数可以帮你解决这个问题.比如: >>> import heapq >>&g ...
- Python: 没有switch-case语句
初学Python语言,竟然很久才发现Python没有switch-case语句 官方的解释说,“用if... elif... elif... else序列很容易来实现 switch / case 语句 ...
- Spring,Struts2,MyBatis,Activiti,Maven,H2,Tomcat集成(二)——Struts2集成
1. pom.xml文件添struts2依赖jar包: <!-- 与Struts2集成必须使用 --> <dependency> <groupId>org.spri ...
- linux常用命令:grep 命令
Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全局正则表达 ...
- linux常用命令:ln 命令
ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同步的链接.当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在 ...
- 发布QT exe
https://blog.csdn.net/u014453443/article/details/85837138
- office2007-安装程序找不到office.zh-cn\*.文件
在同时安装vs2008 和 office2007 有可能会遇到个问题(如果现在安装office2007,在安装vs2008 不会出现问题, 反正会出现下面问题) 在安装office2007时总是提示“ ...
- Vue源码解析之数组变异
力有不逮的对象 众所周知,在 Vue 中,直接修改对象属性的值无法触发响应式.当你直接修改了对象属性的值,你会发现,只有数据改了,但是页面内容并没有改变. 这是什么原因? 原因在于: Vue 的响应式 ...