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. BCB 串口控件的使用 TComm

    昨天工作用到了串口通信,MMP的,昨天懵逼了一下午,今天终于整通了,身为菜鸟,大师们是不懂这些心痛的. 进入主题:使用BCB提供的控件TComm编程方便且简单,TComm位于System分类里面.   ...

  2. 网页中自适应的显示PDF

    PDF格式呢,是一个高大的新式,如何在不同的浏览器中自适应显示,是一个值得研究的问题. 这里说明重点部分:获取浏览器宽高. IE中: document.body.clientWidth ==> ...

  3. Trove系列(一)—入门篇

    概述DBaaS是目前云计算服务的重要部分,数据库作为一种特殊的应用程序,在应用中普遍存在.而其独特性不仅在于普遍性,而且其性能对应用的表现是至关重要的.数据库的通用性和重要性使得维护一个健壮的数据库实 ...

  4. POJ3581 后缀数组

    http://poj.org/problem?id=3581 这题说是给了N个数字组成的序列A1 A2 ..An 其中A1 大于其他的数字 , 现在要把序列分成三段并将每段分别反转求最小字典序 以后还 ...

  5. Description Resource Path LocationType Java compiler level does not match the version of the instal

    从别的地方导入进来的maven项目报: Description Resource Path Location TypeJava compiler level does not match the ve ...

  6. $好玩的分词——python jieba分词模块的基本用法

    jieba(结巴)是一个强大的分词库,完美支持中文分词,本文对其基本用法做一个简要总结. 安装jieba pip install jieba 简单用法 结巴分词分为三种模式:精确模式(默认).全模式和 ...

  7. Python入门之logging模块

    本章目录: 一.logging模块简介 二.logging模块的使用 三.通过JSON或者YMAL文件配置logging模块 ===================================== ...

  8. 01: RestfulAPI与HTTP

    1.1 RestfulAPI与HTTP简介 1.什么是RestfulAPI 1.REST直接翻译:表现层状态转移,实质就是一种面向资源编程的方法 2.REST描述的是在网络中client和server ...

  9. C_Learning (1)

    /数据类型及占用字节 char   1个字节{-128~127} int    2.4个字节,取决于平台是16位还是32位机子{-65536~65535} short int  2个字节{-32768 ...

  10. html模板生成静态页面及模板分页处理

    它只让你修改页面的某一部分,当然这"某一部分"是由你来确定的.美工先做好一个页面,然后我们把这个页面当作模板(要注意的是这个模板就没必要使用EditRegion3这样的代码了,这种 ...