Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56910    Accepted Submission(s): 26385

Problem Description
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.

 
Input
Input 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.
 
Output
For 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
 
题意:有N个数字构成的序列,求最大递增子段和,即递增子序列和的最大值,思路就是定义dp[i],表示以a[i]结尾的最大递增子段和,双重for循环,每次求出以a[i]结尾的最大递增子段和。
 
#include<iostream>
#include<string.h>
using namespace std;
int a[],dp[];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n;
while(cin>>n&&n!=)
{
for(int i=;i<n;i++)
cin>>a[i];
memset(dp,,sizeof(dp));
dp[]=a[];
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
{
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+a[i]);
}
dp[i]=max(dp[i],a[i]); }
int ans=dp[];
for(int i=;i<n;i++)
ans=max(ans,dp[i]);
cout<<ans<<endl;
}
return ;
}

最新文章

  1. jQuery系列:Ajax
  2. Linux从零单排(一):Google Chrome的安装
  3. (转)TortoiseSVN客户端重新设置用户名和密码
  4. spring boot单元测试(转)
  5. iOS开发——OC篇&amp;协议篇/NSCoder/NSCoding/NSCoping
  6. yii项目开发项目常用技巧和方法汇总
  7. labview 移位寄存器、隧道、索引隧道的区别
  8. POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)
  9. remastersys
  10. Quiz 6a Question 7————An Introduction to Interactive Programming in Python
  11. NOIP 2017 Day 0. 游记
  12. Java开发知识之Java面相对象
  13. (办公)SpringBoot和swagger2的整合.
  14. PHP博大精深,入门容易,精通难,怎么才能真正学好PHP
  15. 提高CPU使用率100%
  16. 你真的了解String的常见API吗?
  17. mysql 5.5 数据库 utf8改utf8mb4
  18. 第5月第10天 node.js的request模块
  19. McAfee 与 360使用感受
  20. Windows下Sqlplus中显示乱码

热门文章

  1. 076、Java数组之定义数组
  2. php面向对象的三大特性——封装、继承、多态
  3. 全程2分钟!教你如何免费下载Windows 10
  4. 超大数据量操作 java程序优化[转载]
  5. Vue项目中v-for无法渲染数据
  6. JAVA开源爬虫列表及简介
  7. python2学习------基础语法5(文件操作)
  8. UVALive 6853(dp)
  9. HihoCoder 1245:王胖浩与三角形 三角形边长与面积
  10. 怎样管理Exchange Server 2013资源邮箱