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 ...
随机推荐
- 初次使用git上传代码(转)
转自 http://www.cnblogs.com/cxk1995/p/5800196.html 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我 ...
- #C++初学记录(ACM试题2)
Max Sum Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-seq ...
- c语言中strcpy与strlen函数对字符串最后的'\0'的处理
对于strcpy来说,它会把字符串最后的‘\0’一起拷贝 对于strlen来说,它计算字符串长度的时候不会把最后的‘\0’计算进去
- vs调试程序时发现变量、类等程序找不到混乱问题
vs中不能同时打开两个解决方案名称相同的程序,否则会运行时出现混乱,比如变量监测不到,类的属性不全等问题
- 【Redis学习之一】Redis
环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 一.Redis入门介绍 数据存储的发展:文件存储--> ...
- python 有道翻译
import requests import time import random import hashlib i = str(int(time.time()*1000)+random.randin ...
- Java SE 基础知识(一)
一.基础知识 1. Java SE : Java Standard Edition Java ME : Java Micro Edition Java EE : Java Enterprise Edi ...
- Js基础知识2-对象、对象属性全解
Object对象 Object对象包含如下属性和方法,也就意味着一切对象(函数也是对象)都包含如下方法. 每种方法和属性在不同的对象中有不同的作用,并不是每种对象都有使用每个方法的必要. 下面是Obj ...
- 查询oracle数据库里面所有的表名
如果是当前用户,"select * from tab"即可
- SQL学习之简单增删改查
SQL最常用的语句,就是增删改查: 增删改查的对象,分别是库(文件夹),表(文件),表的内容(表的记录): 一.创建一个基本的表 #create table Student_Info (Name VA ...