题目链接:  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. iOS 的 APP 如何适应 iPhone 5s/6/6Plus 三种屏幕的尺寸?(转)

    原文:http://www.niaogebiji.com/article-4379-1.html?utm_source=tuicool 初代iPhone 2007年,初代iPhone发布,屏幕的宽高是 ...

  2. mac隐藏或显示文件

    1,显示方法:在“终端” 输入命令 defaults write com.apple.finder AppleShowAllFiles TRUE killall Finder 重启Finder,系统隐 ...

  3. iOS多线程编程指南(一)关于多线程编程(转)

    原文:http://www.dreamingwish.com/article/ios-multi-threaded-programming-a-multi-threaded-programming.h ...

  4. android setCompoundDrawables和setCompoundDrawablesWithIntrinsicBounds差别

    手工设置文本与图片相对位置时.经常使用到例如以下方法: setCompoundDrawables(left, top, right, bottom) setCompoundDrawablesWithI ...

  5. android手动改动density(dpi)的方法

    Android系统中会依据屏幕分辨率范围,制定默认的density,既320(xhdpi),那么我们也能够手动改动density. 改动的方式在system.prop中改动ro.sf.lcd_dens ...

  6. CAD创建不规则形状视口

    选择CAD模型空间中多段线,在指定的布局中创建视口,方法如下: /// <summary> /// 创建视口 /// </summary> /// <param name ...

  7. bootstarp基本模板

    <!DOCTYPE html><!--html5文档格式--> <html lang="zh-CN"><!--申明语言是中文简体--> ...

  8. 《think in python》学习-6

    think in python 有返回函数 我们使用过的内置函数中,有一部分会返回结果,比如 math的 返回值 我们写一个有返回值的函数,计算给定半径的圆的面积,例如这个: def area(rad ...

  9. oracle误删除数据的恢复方法

    学习数据库时,我们只是以学习的态度,考虑如何使用数据库命令语句,并未想过工作中,如果误操作一下,都可能导致无可挽回的损失.当我在工作中真正遇到这些问题时,我开始寻找答案. 今天主要以oracle数据库 ...

  10. ubuntu远程windows服务器

    ubuntu端: sudo apt-get install rdesktop windows端: 需要允许此windows远程访问.我的windows是windows server2012,基本操作: ...