A - Super Jumping! Jumping! Jumping!

Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.

The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.

InputInput contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
OutputFor each case, print the maximum according to rules, and one line one case.
Sample Input

3 1 3 2
4 1 2 3 4
4 3 3 2 1
0

Sample Output

4
10
3
 题目大意:求升序子序列的最大和
 #include<bits/stdc++.h>
using namespace std; int dp[];//dp用于存放从数组头到此为止的最大升序子序列和
int n, a[];
int maxn; int main(){
while(~scanf("%d", &n) && n){
maxn = ;
for(int i=; i<n; i++){
scanf("%d", a+i);
dp[i] = a[i];//将每个ai的值赋予dpi
}
for(int i=; i<n; i++){
for(int j=; j<i; j++){
if(a[i] > a[j] && dp[i] < dp[j]+a[i])
dp[i] = dp[j] + a[i];
if(dp[i] > maxn) maxn = dp[i];
}
} printf("%d\n",maxn);
}
}

是今天刚学的dp,告诉我们这类题目没有固定的模板,更重要的是思维和思考,借助dp这样的一个数组,去存放你需要求或相关的变量。既然没有固定模板,则需要更多的练习,去接触更多样式的巧妙的题目

最新文章

  1. APEX:对object中数据进行简单处理?
  2. webservice jsonp格式调用
  3. TP-Link 无线路由器设置图文教程----怎么设置TP-Link无线路由器图解
  4. Android 进度条改变图片透明度
  5. nide.js(二)文件I/O
  6. 模拟赛20181016 Uva 1040 状压+搜索 2005 ACM world final problem c
  7. 代码混淆工具——Virbox Protector Standalone
  8. java List递归排序,传统方式和java8 Stream优化递归,无序的列表按照父级关系进行排序(两种排序类型)
  9. Android--小游戏
  10. python获取esxi的磁盘使用率信息
  11. 饿了么vue-cli3.0+cube-ui笔记
  12. php 对象转数组
  13. 现在的企业用到的Java开发主流框架有哪些
  14. 2018.08.17 bzoj4653: [Noi2016]区间(线段树+尺取法)
  15. 指针的引用(*&amp;)与指针的指针(**)
  16. 1 win10双系统安装ubuntu16.04和18.04(问题详细记录)
  17. UnicodeEncodeError: &#39;gbk&#39; codec can&#39;t encode character ...
  18. Splash 笔记
  19. java enum naming rules &amp; Pascal case, Camel case, Uppercase
  20. IOS 线程的总结(及cell的图片下载)

热门文章

  1. Javascript小白经典题型(二)
  2. HDU_5729_rmq+二分
  3. c语言小游戏-三子棋的完成
  4. thinkphp远程执行漏洞的本地复现
  5. qt creator源码全方面分析(2-10-2)
  6. kali重置root密码
  7. 《C/C++实现Console下的加载进度条模拟[美观版]》
  8. Vue实战之【企业开发常见问题】
  9. web测试和app测试
  10. 让div充满整个body