51nod 1270 数组的最大代价(基础dp)
来源:互联网 发布:思归软件下载 编辑:程序博客网 时间:2024/06/05 11:38
先用记忆化搜索写的,搜错了。。看了下讨论版,写成了如下的形式。
每个Ai取1或者Bi,然后dp。。。。dp[i][0]表示前i个数字且第i个数字取1的最大代价,dp[i][1]表示前i个数字且第i个数字取Bi的最大代价。
#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int MAXN = 50010;int num[MAXN];int dp[MAXN][2];int n;int main(){ //freopen("in","r",stdin); ios::sync_with_stdio(false); cin >> n; for(int i = 1; i <= n; ++i) cin >> num[i]; for(int i = 2; i <= n; ++i) { dp[i][0] = max(dp[i-1][0],dp[i-1][1] + abs(1-num[i-1])); dp[i][1] = max(dp[i-1][0] + abs(num[i]-1),dp[i-1][1] + abs(num[i]-num[i-1])); } cout << max(dp[n][0],dp[n][1]) << endl; return 0;}
0 0
- 51nod 1270 数组的最大代价(基础dp)
- 51nod 1270 数组的最大代价(DP)
- 51nod 1270 数组的最大代价 dp
- 【51Nod】1270 - 数组的最大代价(dp)
- 51nod 1270 数组的最大代价(DP)
- 【dp】51nod 1270 数组的最大代价
- 51nod 1270:数组的最大代价
- 51NOD 1270 数组的最大代价
- 51nod-【1270 数组的最大代价】
- 51nod 1270 数组的最大代价
- 51Nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod- 1270 数组的最大代价
- 1270 数组的最大代价 51NOD
- 51Nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 51nod 1270 数组的最大代价
- 【51nod】1270 数组的最大代价
- linux(deepin15.4)下部署集群RabbitMQ消息队列(二)
- voip---linphone 分析
- netty, ByteBuf 转 String
- 任意输入两个数,求其最大公约数和最小公倍数
- apache bench做web压力测试详解
- 51nod 1270 数组的最大代价(基础dp)
- 先序创建二叉树及三种遍历
- 牛顿法(Newton's method)
- JS页面跳转和js对iframe进行页面跳转、刷新
- tensorflow使用tensorboard实现数据可视化
- simplexml_load_string报错:XML declaration allowed only at the start of the document
- min_free_kbytes
- caffe --Multi-GPU Usage
- Android Studio使用USB真机调试