Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 24374    Accepted Submission(s): 10740


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

解题心得:

1、就是求一个最长上升子序列的和,子序列不一定要相邻,这个动态规划可以先看前三项,dp[1] = num[1],这是num[2]如果大于num[1],dp[2] = dp[1] + num[2],否则dp[2] = num[2],在看第三个num[3],如果num[3]大于num[2]那么dp[3]
= dp[2] + num[3],如果num[3]大于num[1],dp[3] = dp[1] + num[3],如果num[3]不大于num[2]同时也不大于num[1],dp[3] = num[3]。说了这么多其实就是一个意思,用之前的每一个数和当前的数比较,比当前数小的就加上dp【之前数】,不然就等于当前数。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1010;
long long num[maxn];
long long dp[maxn];
void pre_num(int n)
{
memset(dp,0,sizeof(dp));
num[0] = 0;
for(int i=1;i<=n;i++)
scanf("%d",&num[i]);
} void get_ans(int n)
{
long long Max = -1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=i;j++)
{
if(num[j] < num[i])
dp[i] = max(dp[i],dp[j]+num[i]);//之前数比当前数小,就加上当前数到之前数的和上面
}
dp[i] = max(dp[i],num[i]);//之前数都不比当前数小的情况下直接就是当前数
if(dp[i] > Max)//记录最大的那个和
Max = dp[i];
} printf("%lld\n",Max);
}
int main()
{
int n;
while(scanf("%d",&n) && n)
{
pre_num(n);
get_ans(n);
}
}

动态规划:HDU1087-Super Jumping! Jumping! Jumping!(最大上升子序列和)的更多相关文章

  1. HDU1087 - Super Jumping! Jumping! Jumping!【动态规划】

    zh成功的在他人的帮助下获得了与小姐姐约会的机会,同时也不用担心被非"川大"的女票发现了,可是如何选择和哪些小姐姐约会呢?zh希望自己可以循序渐进,同时希望挑战自己的极限,我们假定 ...

  2. 解题报告 HDU1087 Super Jumping! Jumping! Jumping!

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. HDU1087:Super Jumping! Jumping! Jumping!(DP)

    Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very ...

  4. HDU1087 Super Jumping! Jumping! Jumping! 最大连续递增子段

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  5. kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  6. HDU1087 Super Jumping! Jumping! Jumping! —— DP

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limi ...

  7. hdu1087 Super Jumping! Jumping! Jumping!---基础DP---递增子序列最大和

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 题目大意: 求递增子序列最大和 思路: 直接dp就可以求解,dp[i]表示以第i位结尾的递增子 ...

  8. HDU1087 Super Jumping! Jumping! Jumping!(LIS)

    题目意思: http://acm.hdu.edu.cn/showproblem.php? pid=1087 此题的意思求最长上升子序列的和. 题目分析: 在求最长上升子序列的时候,不在保存最长的个数, ...

  9. HDu1087 Super Jumping! Jumping! Jumping!

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 分析:简单dp:dp[i] = max (dp[i], dp[j] + a[i]) 1 #inc ...

  10. HDU 1087 Super Jumping! Jumping! Jumping!(最长上升子序列,dp)

    以下引用自:http://www.cnblogs.com/Lyush/archive/2011/08/31/2161314.html沐阳 该题可以算是一道经典的DP题了,题中数据是这样的.以 3 1 ...

随机推荐

  1. Elasticsearch如何安装中文分词插件ik

    elasticsearch-analysis-ik 是一款中文的分词插件,支持自定义词库. 安装步骤: 1.到github网站下载源代码,网站地址为:https://github.com/medcl/ ...

  2. 关于Arduino项目的构建思想-转自openbook开源杂志

  3. 《Head First 设计模式》之适配器模式与外观模式

    适配器模式(Adapter) 适配器(adapter-pattern):将一个类的接口,转换成客户期望的另一个接口.适配器让原来接口不兼容的类可以合作无间.两种形式: 对象适配器(组合) 类适配器(多 ...

  4. 一位学长的学习建议(java方向)

    1.前台总得有个拿的出手的页面能力吧,ajax,jquery不说精通但是至少能看懂,能根据业务需求来改吧. 2.数据库方面至少得玩过mysql,DB2,Oracle中的两个以上吧.hibernate或 ...

  5. idea字体模糊

    用jdk1.8的jre替换idea的jre64,但是记得在lib里加上jdk的lib中的tools.jar. 如图: 然后 将原来jre64的TOOLS.jar拷贝到替换后的jre的lib目录下,重启 ...

  6. app之间的跳转和传参问题

    app 之间跳转和传参: 首先 创建2个app   formApp (需要跳转到另外app的项目)     toApp(被跳转的项目) 一:在toApp 项目中的操作: 1:创建URLSchemes ...

  7. 题解 P1280 【尼克的任务】

    传送门 f[i]表示i~n的最长空闲时间: 如果当前无任务就休息一秒(f[i]=f[i+1]+1): 否则f[i]=max(f[i],f[i+当前工作时间]); 用结构体来记录,我们对于每一个时刻开一 ...

  8. Java代码工具箱_用Set给List/Vector去重

    参考 方法一:需要2个容器,1个迭代去重,1个作为结果容器. 此方法其实想法比较简单也是正常思路: package com.yonyou.test; import java.util.List; im ...

  9. java中利用JOptionPane类弹出消息框的部分例子

    转: http://www.cnblogs.com/wangxiuheng/p/4449917.html http://blog.csdn.net/penjie0418/article/details ...

  10. 学习笔记 | java反序列化漏洞分析

    java反序列化漏洞是与java相关的漏洞中最常见的一种,也是网络安全工作者关注的重点.在cve中搜索关键字serialized共有174条记录,其中83条与java有关:搜索deserialized ...