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的更多相关文章

  1. Codeforces 855B:Marvolo Gaunt's Ring(枚举,前后缀)

    B. Marvolo Gaunt's Ring Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaun ...

  2. Marvolo Gaunt's Ring(巧妙利用前后缀进行模拟)

    Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as h ...

  3. B. Marvolo Gaunt's Ring 前缀后缀

    B. Marvolo Gaunt's Ring 这种一般只有三个的都可以处理前缀和后缀,再枚举中间这个值. 这个和之前写过的C. Four Segments 前缀后缀 处理方式很像. #include ...

  4. 【ST】【CF855B】 Marvolo Gaunt's Ring

    传送门 Description 给定三个数 \(p~,~q~,~r~\),以及一个数组 \(a\), 找出三个数 \(i~,~j~,~k\) ,其中 \(i~\leq~j~\leq~k\) 最大化 \ ...

  5. 【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]最大; [题解] /*     有一个要 ...

  6. CodeForces - 855B ring 前缀和

    邓布利多教授正在帮助哈利摧毁魂器.当他怀疑一个魂器出现在那里时,他去了冈特沙克.他看到Marvolo Gaunt的戒指,并将其确定为魂器.虽然他摧毁了它,但仍然受到诅咒的影响.斯内普教授正在帮助邓布利 ...

  7. codeforce 855B

    B. Marvolo Gaunt's Ring time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  8. Manthan, Codefest 17

    A. Tom Riddle's Diary time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Harry Potter

    Names appearing in "Harry Potter" 1.Harry Potter ①Harry is from Henry. ②Harry is related t ...

随机推荐

  1. file_get_post实现post请求

    function Post($url, $post = null){     $context = array();     if (is_array($post)) {       ksort($p ...

  2. VS2010/MFC编程入门之三十一(常用控件:树形控件Tree Control 下)

    前面一节讲了树形控件Tree Control的简介.通知消息以及相关数据结构,本节继续讲下半部分,包括树形控件的创建.CTreeCtrl类的主要成员函数和应用实例. 树形控件的创建 MFC为树形控件提 ...

  3. zw版【转发·台湾nvp系列Delphi例程】HALCON HistoToThresh2

    zw版[转发·台湾nvp系列Delphi例程]HALCON HistoToThresh2 procedure TForm1.Button1Click(Sender: TObject);var imag ...

  4. uva1411 最小值转最大值+二分图匹配

    这题给了n个白点和n个黑点坐标,计算出他们两两配对的总路程最少, 我们算出他们之间的距离,为d,然后 w[j][i]=-d; 就将求最小值转化为求最大值,然后采用km进行匹配计算 #include & ...

  5. Maven的scope的值

    Maven的依赖范围 在pom.xml文件中,有个元素是scope,用来表示依赖的范围.之所以会有依赖范围,是因为Maven在编译.测试和运行项目时会各自使用一套classpath,依赖范围就是用来控 ...

  6. QPropertyAnimation 几行代码快速制作流畅的动画效果

    QPropertyAnimation Class 官方英文文档[点击前往] QPropertyAnimation Class 中文译文文档[点击前往]   简介 QPropertyAnimation ...

  7. C/C++之单例模式实现

    /*** * 保证一个类仅有一个实例,并提供一个访问它的全局访问点 */ #include <iostream> #include <string> using namespa ...

  8. jenkin环境搭建

      Jenkins是一个用Java编写的开源的持续集成(CI)工具,可持续.自动地构建/测试软件项目,监控一些定时执行的任务.具有开源,支持多平台和插件扩展,安装简单,界面化管理等特点. 1.下载并解 ...

  9. Linux 系统版本信息

    1.# uname -a   (Linux查看版本当前操作系统内核信息) 2.# cat /proc/version (Linux查看当前操作系统版本信息) 3.# cat /etc/issue  或 ...

  10. 10:Python2与Python3比较

    1.print 函数 1. print语句没有了,取而代之的是print()函数. Python 2.6与Python 2.7部分地支持这种形式的print语法. 2.Unicode 1.  在pyt ...