Manthan, Codefest 17 B. Marvolo Gaunt's Ring(前后缀/dp)
来源:互联网 发布:sql 日期格式 编辑:程序博客网 时间:2024/06/05 11:45
题目:http://codeforces.com/contest/855/problem/B
题意:给一个数组,让求p·ai + q·aj + r·a 的最大值(1 ≤ i ≤ j ≤ k ≤ n)
思路:
维护最大前后缀
dp参考here
代码:
#include<bits/stdc++.h>using namespace std;const int N = 100005;int a[N];long long L[N],R[N];int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; long long p,q,r; cin >> n >> p >> q >> r; for(int i = 1;i <= n;i++) cin >> a[i]; L[1] = a[1]*p;R[n] = a[n]*r; for(int i = 2;i <= n;i++) L[i] = max(L[i-1],a[i]*p); for(int i = n-1;i >= 1;i--) R[i] = max(R[i+1],a[i]*r); long long maxn = -(1ll<<63); for(int i = 1;i <= n;i++) maxn = max(maxn , L[i]+a[i]*q+R[i]); cout << maxn << "\n"; return 0;}
阅读全文
0 0
- Manthan, Codefest 17 B. Marvolo Gaunt's Ring(前后缀/dp)
- codeforces Manthan, Codefest 17 B Marvolo Gaunt's Ring(dp)
- Manthan, Codefest 17 Marvolo Gaunt's Ring
- Manthan, Codefest 17: B. Marvolo Gaunt's Ring
- codeforces Manthan, Codefest 17 B.Marvolo Gaunt's Ring (简单dp)
- Codeforces 855 B Marvolo Gaunt's Ring(dp)
- Codeforces 855 B Marvolo Gaunt's Ring
- CF 855B. Marvolo Gaunt's Ring【枚举||递推】
- Manthan, Codefest 17 B
- Manthan, Codefest 17 E. Salazar Slytherin's Locket 数位DP
- Manthan, Codefest 17 E. Salazar Slytherin's Locket(数位DP)(进制)
- Manthan, Codefest 17 E. Salazar Slytherin's Locket(数位DP)
- Manthan, Codefest 17 C. Helga Hufflepuff's Cup(树形DP)
- Manthan, Codefest 17: C. Helga Hufflepuff's Cup(树形DP)
- Manthan, Codefest 17: E. Salazar Slytherin's Locket(数位DP)
- Manthan, Codefest 17-C-Helga Hufflepuff's Cup(树形DP)
- Manthan, Codefest 17-E-Salazar Slytherin's Locket(数位DP)
- Manthan, Codefest 17 B-F题目详解
- 英语语法基础篇-书写规则
- Coursera 吴恩达 Deep Learning 第2课 Improving Deep Neural Networks 第一周 编程作业代码 Initialization
- 准备到的中秋节
- opencv小问题
- UVa221 Urban Elevations 细述原理
- Manthan, Codefest 17 B. Marvolo Gaunt's Ring(前后缀/dp)
- POJ 3985 Knight's Problem(bfs+hash+剪枝)
- oracle之函数
- mysql查询所有分类的前5行结果
- 栈和队列——构造数组的MaxTree(java实现)
- 用js写了一个判断矩形相交的函数
- 经典卷积神经网络(CNN)实现MNIST分类(基于LeNet-5模型)
- leetcode 637. Average of Levels in Binary Tree
- 微信小程序swiper滑动页面