Super Jumping! Jumping! Jumping!

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

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
 
题意:求最大 上升子序列的和
 
题解;类比求最长上升子序列的长度  dp[i] 代表 以a[i]为结尾的 上升子序列的最大和
        当增加第i个数a[i]时 只需要在 j= 1~i-1中寻找在 a[j]<a[i]的情况下的 dp[j]的最大值maxn  
        然后更新 dp[i]=maxn+a[i]  存储 dp[i]的最大值 输出
 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n;
int a[];
int ans[];
int exm;
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==)
break;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
ans[i]=a[i];
}
int maxlen=-;
for(int i=;i<=n;i++)
{
int maxn=;
for(int j=;j<i;j++)
{
if(a[j]<a[i]&&maxn<ans[j])
{
maxn=ans[j];
}
}
ans[i]=maxn+a[i];
if(ans[i]>maxlen)
{
maxlen=ans[i];
exm=i;
}
}
cout<<maxlen<<endl;
}
return ;
}

最新文章

  1. [LeetCode] Single Number 单独的数字
  2. 洛谷P2409 Y的积木
  3. 使用百度网盘+Git,把版本控制托管到云端
  4. JSONP的小示例
  5. Latex及Beamer
  6. Struts+Spring+Hibernate进阶开端(一)
  7. 简单解析nestJS目录
  8. Django中views笔记
  9. 破解网页右键被禁止js
  10. [CSL 的字符串][栈,模拟]
  11. flask框架的教程--虚拟环境的安装[一]
  12. C语言实现二叉树的建立、遍历以及表达式的计算
  13. bootstrap 列表--水平定义列表
  14. tar 打包当前目录下文件但不包括该录
  15. Origin绘制双Y轴图的方法
  16. ORACLE递归查询(适用于ID,PARENTID结构数据表)
  17. codevs 1795 金字塔 2
  18. MikroTik RouterOS 6.x版本开始支持使用img镜像安装(U盘安装的终极解决方法)
  19. 在虚拟机中安装Ubuntu详细过程
  20. 眼前一亮!十八款新潮而又独特的网站Header设计

热门文章

  1. LVS+Keepalived-DR模式负载均衡高可用集群
  2. 微信公众号支付java版本
  3. 【Mysql】给mysql配置远程登录
  4. ubuntu配置命令
  5. 1016-01-首页16-计算配图的frame----MJExtention的使用
  6. 001---web应用程序
  7. [USACO12JAN]视频游戏的连击Video Game Combos(AC自动机+DP)
  8. Spring.net Ioc 依赖注入
  9. Service Intent must be explicit
  10. django中间件CsrfViewMiddleware源码分析,探究csrf实现