Super Jumping! Jumping! Jumping!

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

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(赶脚自己好菜啊~~)
     只要把状态转移方程怼出来就可以了。对于这题来说可以定义一个dp数组
     dp[i] 表示前i个整数组成的子串的最大上升子序列和
     状态方程:dp[i]=max{dp[j]}+a[i]; 其中,0<=j<i,a[i]>a[j] ;
 
 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n;
long long a[],dp[]; // dp[i] 储存从0到i的最大上升子序列的和
long long LIS() // 最大上升子序列和
{
int i,j;
long long sum = , maxx;
for (i = ; i < n; i ++)
{
dp[i] = a[i]; // dp[i]的初值为a[i]
maxx = ;
for (j = ; j < i; j ++) // 找出i之前的最大dp[i](并保证a[j] < a[i])
{
if (a[j] < a[i])
maxx = max(dp[j],maxx);
}
dp[i] += maxx;
sum = max(sum,dp[i]); // sum为最大上升子序列的和
}
return sum;
}
int main ()
{
while (scanf("%d",&n),n)
{
for (int i = ; i < n; i ++)
scanf("%lld",&a[i]);
printf("%lld\n",LIS());
}
return ;
}

最新文章

  1. 小甲鱼PE详解之IMAGE_DOS_HEADER结构定义即各个属性的作用(PE详解01)
  2. CSS 超出隐藏问题
  3. Elasticseach部分语法总结
  4. iOS本地数据存取
  5. laravel5的坑
  6. angular的$http.post()提交数据到Java后台接收不到参数值问题的解决方法
  7. linux路由表
  8. React-typescript-antd 常见问题
  9. IdentityServer4(5)- 包和构建
  10. 【CF981D】Bookshelves(贪心,动态规划)
  11. PCB行业研究
  12. lua -- encode and decode
  13. php中__get()和__set的用法
  14. Android:手把手教你打造可缩放移动的ImageView(上)
  15. 【BZOJ 4665】 4665: 小w的喜糖 (DP+容斥)
  16. wampserver无法打开http://127.0.0.1/
  17. logger模块的使用
  18. dedecms图片绝对路径(附件绑定域名)的设置方法
  19. OpenCV 2.4.9 学习笔记(4)—— 像素类型与Templates的限制使用
  20. 倍福TwinCAT(贝福Beckhoff)基础教程 松下官方软件开启报错伺服未就绪怎么办

热门文章

  1. selenium(python)用HTMLTestRunner导出报告(断言)信息的显示
  2. 分布式文件系统之FastDFS
  3. python创建目录并更改权限的代码
  4. MVC返回数据流,ajax接受并保存文件
  5. vue项目里登录界面实现回车登录
  6. java 的继承
  7. js中this那些事儿
  8. Kettle 中生成随机数 或者GUID唯一标识符
  9. (转)基于CentOS 7安装Zabbix 3.4和Zabbix4.0
  10. selenium+Python(cookie处理)