Codeforces 855 B Marvolo Gaunt's Ring(dp)
来源:互联网 发布:淘宝e客服怎么开通 编辑:程序博客网 时间:2024/06/05 12:00
题目地址
题意:给你4个数n,p,q,r,然后告诉你n个数a[],让你求出满足最大的 p·ai + q·aj + r·ak 的i,j,k,并且i<=j<=k(重点)
思路:我们可以发现j在中间,我们只要维护一个前缀最大值和前缀最小值以及后缀最大值和后缀最小值,这样的话我们枚举这个j就好了,然后判断是正还是负,选取要最大值还是最小值,最后求出这个的最大值就好了。
#include <iostream>#include <cstring>#include <string>#include <queue>#include <vector>#include <map>#include <set>#include <cmath>#include <cstdio>#include <algorithm>#include <iomanip>#define N 100010#define M 2000010//双倍#define LL __int64#define inf 0x3f3f3f3f3f3f3f3f#define lson l,mid,ans<<1#define rson mid+1,r,ans<<1|1#define getMid (l+r)>>1#define movel ans<<1#define mover ans<<1|1using namespace std;const LL mod = 1000000007;const double eps = 0.001;LL n, a, b, c, num[N], sum;LL nummin[N], nummax[N], premin[N], premax[N];int main() { cin.sync_with_stdio(false); while (cin >> n >> a >> b >> c) { nummax[0] = -1e18; nummin[0] = 1e18; premax[n + 1] = -1e18; premin[n + 1] = 1e18; for (int i = 1; i <= n; i++) { cin >> num[i]; nummax[i] = max(nummax[i - 1], num[i]); nummin[i] = min(nummin[i - 1], num[i]); } for (int i = n; i >= 1; i--) { premax[i] = max(premax[i + 1], num[i]); premin[i] = min(premin[i + 1], num[i]); } sum = -4e18; for (int i = 1; i <= n; i++) { LL ans = 0; if (a >= 0) { ans += a*nummax[i]; } else { ans += a*nummin[i]; } if (c >= 0) { ans += c*premax[i]; } else { ans += c*premin[i]; } sum = max(sum, num[i] * b + ans); } cout << sum << endl; } return 0;}
阅读全文
0 0
- Codeforces 855 B Marvolo Gaunt's Ring(dp)
- Codeforces 855 B Marvolo Gaunt's Ring
- codeforces Manthan, Codefest 17 B Marvolo Gaunt's Ring(dp)
- codeforces Manthan, Codefest 17 B.Marvolo Gaunt's Ring (简单dp)
- CF 855B. Marvolo Gaunt's Ring【枚举||递推】
- Manthan, Codefest 17 B. Marvolo Gaunt's Ring(前后缀/dp)
- Manthan, Codefest 17: B. Marvolo Gaunt's Ring
- Manthan, Codefest 17 Marvolo Gaunt's Ring
- CodeForces 235B Let's Play Osu!(概率dp)
- codeforces 855B DP
- Codeforces Round #248 (Div. 1) B. Nanami's Digital Board(DP+ 双指针/单调栈)
- codeforces 235B. Let's Play Osu! (概率与期望DP)
- Codeforces 235B Let's Play Osu! 概率dp(水
- codeforces 235B Let's Play Osu! 概率dp
- Codeforces 235B Let's Play Osu! 概率dp
- Codeforces 855 C. Helga Hufflepuff’s Cup (树形dp)
- CodeForces 855C Helga Hufflepuff's Cup(树形dp)
- codeforces 855C Helga Hufflepuff's Cup (树形dp)
- 第七周 【项目2
- NOIP模拟(20171024)T3 数学
- linux mysql表格大小写的问题
- bzoj4446 小凸玩密室【树形dp】
- 洛谷2119 魔法阵
- Codeforces 855 B Marvolo Gaunt's Ring(dp)
- Codeforces 877 A Alex and broken contest
- 7种失败的职场人
- ViewPager使用中遇到的问题
- NOIP-2014 联合权值
- BZOJ3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛
- MySQL双主一致性架构优化
- HDU
- 编程范式13听课笔记——缓冲区溢出和C++接受可变参数