【51nod】1270 数组的最大代价
来源:互联网 发布:mac珊瑚红口红效果图 编辑:程序博客网 时间:2024/05/22 19:03
题目:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1270
分析:
要么取峰值要么取谷值, dp[n][0],dp[n][1] 分别表示第i位取1或最大值时,最大的代价
代码:
#include<iostream>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;const int Maxn=50010;int a[Maxn],dp[Maxn][2];int main(){ int N; cin>>N; for(int i=1;i<=N;i++) { cin>>a[i]; } dp[1][0]=dp[1][1]=0; for(int i=2;i<=N;i++) //为使最大,取值要么谷底‘1’,要么固顶‘a[i]’,dp存储当前与前一位的最大差; { dp[i][0]=max(dp[i-1][0],dp[i-1][1]+abs(a[i-1]-1)); dp[i][1]=max(dp[i-1][0]+abs(a[i]-1),dp[i-1][1]+abs(a[i]-a[i-1])); } cout<<max(dp[N][0],dp[N][1])<<endl; return 0;}
阅读全文
0 0
- 51nod 1270:数组的最大代价
- 51NOD 1270 数组的最大代价
- 51nod-【1270 数组的最大代价】
- 51nod 1270 数组的最大代价
- 51Nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod- 1270 数组的最大代价
- 1270 数组的最大代价 51NOD
- 51Nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 【51nod】1270 数组的最大代价
- 51 nod 数组的最大代价
- 51 nod 1270 数组最大代价
- 51nod 1270 数组的最大代价(DP)
- 51nod 1270 数组的最大代价 (DP_好题)
- 51nod 1270 数组的最大代价 dp
- 51Nod-1270-数组的最大代价
- visual studio 2017社区版安装总是失败的解决
- 【BZOJ】1009 [HNOI2008]GT考试 KMP+DP+矩阵优化
- 树莓派网线连接电脑进行操作
- linux上tomcat启动问题
- SqlClr —— 一次查询多个DB
- 【51nod】1270 数组的最大代价
- hashtable
- JavaSE基础练习
- postgresql技巧
- CocosCreator 创建全局对象 == 同单例效果一致
- org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access
- vue2-highcharts
- 【Miller-Rabin 素数判定】HDU
- web前端pc,mobile复制粘贴功能的实现