【51nod】1270 数组的最大代价
2017-10-09 17:53
316 查看
题目:
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1270分析:
要么取峰值要么取谷值, dp[0],dp
[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 [0],dp [1])<<endl; return 0; }
相关文章推荐
- 51nod 1270 数组的最大代价 dp
- 51NOD 1270 数组的最大代价
- 51Nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价 思路:简单动态规划
- 51nod 1270 数组的最大代价(dp好题)
- 【51Nod】1270 - 数组的最大代价(dp)
- 51Nod-1270-数组的最大代价
- 51nod——1270 数组的最大代价 动态规划解法
- 51nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod- 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价【思维+Dp+滚动数组优化】
- 51nod-【1270 数组的最大代价】
- 51nod 1270 数组的最大代价(DP)
- 51nod 1270:数组的最大代价
- 51nod 1270 数组的最大代价 绝对值取极值问题
- 51nod 1270 数组的最大代价 (DP_好题)