题目链接:  http://acm.swust.edu.cn/contest/0226/problem/1139/

There is a row of n coins whose values are some positive integers c₁, c₂,...,cn, not necessarily distinct. The goal is to pick up the maximum amount of money subject to the constraint that no two coins adjacent in the initial row can be picked up.

Description
Two lines, the first line is n (0< n <=10000), and the second line is value of coin(0< value <= 2^32).

Input
the maximum amount of money.

Output
1
2
6
5 1 2 10 6 2
Sample Input
1
17
Sample Output
Hint
Algorithm Text Book
 
题目大意:就是给你一排数字,不能够拿相邻的数字,问拿的数字的最大和为多少~~
 
思路:估计这老师才讲了dp 算法吧,这组题几乎全是dp(也是醉了)
不能够相邻那么就考虑当前位的前两个数对应的最好状态+当前数,和当前数的前一个数的状态比较,这里的边界dp[0]=0,dp[1]=x[1](x数据元素数组从1开始存贮),
那么可以得到如下dp方程  dp[i] = max(dp[i - 1], dp[i - 2] + x[i]);
 
具体的看代码理解吧~~~
 
 #include <iostream>
using namespace std;
int n, dp[], i, x[];
#define max(a,b) a>b?a:b
int main()
{
cin >> n;
for (i = ; i <= n; i++) cin >> x[i];
dp[] = x[];
for (i = ; i <= n; i++)
dp[i] = max(dp[i - ], dp[i - ] + x[i]);
cout << dp[n] << "\r\n";
return ;
}

dp就是这么牛逼,几行代码就整出了答案~~~

 

[Swust OJ 1139]--Coin-row problem的更多相关文章

  1. [Swust OJ 404]--最小代价树(动态规划)

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  2. [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  3. SWUST OJ NBA Finals(0649)

    NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128   Descri ...

  4. [Swust OJ 1132]-Coin-collecting by robot

          题目链接:          http://acm.swust.edu.cn/problem/1132/ Time limit(ms): 1000 Memory limit(kb): 65 ...

  5. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  6. [Swust OJ 795]--Penney Game

    题目链接:http://acm.swust.edu.cn/problem/795/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  7. [Swust OJ 643]--行列式的计算(上三角行列式变换)

    题目链接:http://acm.swust.edu.cn/problem/643/ Time limit(ms): 1000 Memory limit(kb): 65535   Description ...

  8. [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)

    题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  9. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

随机推荐

  1. 利用PowerDesigner15在win7系统下对MySQL 进行反向project(二)

    利用PowerDesigner15在win7系统下对MySQL 进行反向project 1.打开PowerDesigner,建立新模型.选择Physical Data Model中的Physical ...

  2. 初识Devexpress ChartControl 之 动态添加stepline及TextAnnotation

    最近在用devexpress 第三方软件做项目. devexpress 的控件使用简单.功能强大.类型丰富.界面优美.扩展性强.今天主要是动态生成了一条StepLine.生成后的效果(能力不强,所以做 ...

  3. java 解析json的问题

    本文转载自http://chriszz.sinaapp.com/?p=392 Json就是Javascript notation,可以替代XML,用做数据交互. Json的两种基本表示形式,可以用自动 ...

  4. 利用分布类防止EF更新模型丢失验证信息

    数据库表TT,EF生成的model是这样的.在这里添加代码,从数据库更新模型是会冲掉. //------------------------------------------------------ ...

  5. Mantis 缺陷管理系统配置与安装[Z]

    什么是Mantis MantisBT is a free popular web-based bugtracking system (feature list). It is written in t ...

  6. google base 之MessagePumpForUI

    base库中比较有意思就是这个类了,如同很多界面库一样,创建了一个隐藏窗口来处理需要在界面线程处理的消息,大体原理也就是需要执行task的时候发送一个自定义的消息,当窗口接收到task的时候调用保存起 ...

  7. sf

    #include <stdio.h> #include <time.h> #include <stdlib.h> #define MAXN 150 //最大节点数 ...

  8. SQL Server 完成性检查的顺序

    第一步: 默认值 第二步: 违反not null 限制 第三步: 判断check约束 第四步: 对引用表应用foreign key 检查 第五步: 对被引用表做 foreign key 检查 第六步: ...

  9. DEM 数据下载

    https://centaurus.caf.dlr.de:8443/short_guide/index.html https://centaurus.caf.dlr.de:8443/eoweb-ng/ ...

  10. SD和SDHC和SDXC卡的区别是什么

    SD卡,SDHC卡,SDXC卡区别在规格不一样,SD卡最大支持2GB容量,SDHC 最大支持32GB容量,SDXC 最大支持2TB(2048GB)容量,支持SDXC卡的数码设备是兼容支持SD卡与SDH ...