codeforces Manthan, Codefest 17 B Marvolo Gaunt's Ring(dp)
来源:互联网 发布:大数据培训靠谱吗 编辑:程序博客网 时间:2024/06/06 03:03
碰到能套模板的dp还能套,不能套的基本就死了。这么个水题想了一个多小时猜想到解法。交了没多久就被hack了。又调了半个多小时才发现写错变量类型了。
思路:比较基础的dp,对于p,q,r三个数,单独分开操作的。先是计算p和那n个数的乘积,dp[i]保存的是max(num[1…i] * p)。然后再对q操作,这时dp[i]保存的是max(dp[i-1] ,dp[i] + q * num[i])。对r的操作同q。
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int MAXN = 1e5+10;const LL INF = 8e18;LL num[MAXN];LL dp[MAXN];int main(){ ios::sync_with_stdio(false); LL maxn = - INF; int n; LL p,q,r; dp[0] = - INF; LL now,res = -INF; cin >> n >> p >> q >> r; for(int i = 1; i <= n; ++i) cin >> num[i]; for(int i = 1; i <= n; ++i) { now = p*num[i]; dp[i] = max(dp[i-1],now); } for(int i = 1; i <= n; ++i) { now = q*num[i]; dp[i] = max(dp[i-1],dp[i]+now); } for(int i = 1; i <= n; ++i) { now = r*num[i]; dp[i] = max(dp[i-1],dp[i]+now); res = max(res,dp[i]); } cout << res << endl; return 0;}
阅读全文
0 0
- codeforces 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
- 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
- Codeforces Manthan, Codefest 17 C. Helga Hufflepuff's Cup 树型DP
- Codeforces Manthan Codefest 17 C 855CHelga Hufflepuff's Cup(树型DP)
- Manthan, Codefest 17 E. Salazar Slytherin's Locket 数位DP
- Manthan, Codefest 17 B-F题目详解
- CodeForces Manthan, Codefest 16 B A Trivial Problem 二分
- 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)
- 第三周 项目4 顺序表应用(二)
- MarsBoard全志A20的Android4.2.2系统的编译(分色排版)
- 马走日 (DFS)
- ibatis配置多数据源(仅供参考思路)
- 对称加密算法
- codeforces Manthan, Codefest 17 B Marvolo Gaunt's Ring(dp)
- 文章总结
- [luogu-3379]【模板】最近公共祖先(LCA) 题解
- Python中的异常
- python中常用正则表达式
- 判断闰年
- <倍增lca>codevs 3305 水果姐逛水果街Ⅱ
- 树的同构
- android 权限申请