题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087

Super Jumping! Jumping! Jumping!

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

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[i]表示的是前i个并且包含第i个的最大递增子序列和!给个数据:3 1 4 显然dp[1]=3,dp[2]=1表示两个数的最大值。因为分两种情况讨论,如果第二个数大于第一个数,就加上,即dp[2]=dp[1]+num[2];如果不大,dp[2]=num[2];dp[3]=7表示三个数的最大值。首先比较num[3]和num[1],如果num[3]>num[1],dp[3]=7先存下来,如果num[3]>num[2],dp[3]=5依旧存下来;还有一种如果num[3]比前两个值都小,dp[3]=num[3];最后在存下来的dp[3]中找到一个最大的!呼呼~终于解释差不多了,小伙伴们也屡一下思路吧0.0
 
 
详见代码。
 
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int num[],dp[]; int main ()
{
int n,Max;
while (~scanf("%d",&n))
{
if (n==)
break;
Max=;
memset(dp,,sizeof(dp));
for (int i=;i<n;i++)
{
scanf("%d",&num[i]);
}
dp[]=num[];
for (int i=;i<n;i++)
{
for (int j=;j<i;j++)
{
if (num[i]>num[j])
dp[i]=max(dp[i],dp[j]+num[i]);
}
dp[i]=max(dp[i],num[i]);
}
for (int i=;i<n;i++)
{
Max=max(Max,dp[i]);
}
printf ("%d\n",Max);
}
return ;
}

hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping

    HDU 1087 题目大意:给定一个序列,只能走比当前位置大的位置,不可回头,求能得到的和的最大值.(其实就是求最大上升(可不连续)子序列和) 解题思路:可以定义状态dp[i]表示以a[i]为结尾的上 ...

  2. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

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

  3. HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *

    Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64 ...

  4. hdu 1087 Super Jumping! Jumping! Jumping!(动态规划DP)

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

  5. HDOJ/HDU 1087 Super Jumping! Jumping! Jumping!(经典DP~)

    Problem Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!&quo ...

  6. hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...

  7. DP专题训练之HDU 1087 Super Jumping!

    Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is ve ...

  8. hdu 1087 Super Jumping! Jumping! Jumping! 简单的dp

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

  9. HDU 1087 Super Jumping! Jumping! Jumping! (DP)

    C - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format: ...

随机推荐

  1. Apriori算法详解

    一.Apriori 算法概述Apriori 算法是一种最有影响力的挖掘布尔关联规则的频繁项集的 算法,它是由Rakesh Agrawal 和RamakrishnanSkrikant 提出的.它使用一种 ...

  2. 【Docker 命令】- start/stop/restart命令

    docker start:启动一个或多少已经被停止的容器 docker stop:停止一个运行中的容器 docker restart :重启容器 语法: docker start [OPTIONS] ...

  3. 第一部分shell编程1基础知识

    ls etc/init.d/ shell脚本的路径 ls /usr/local/apache2/ ls /usr/local/apache2/bin/apachectl 1. shell特性命令历史 ...

  4. 《Effective C#》快速笔记(六)- - C# 高效编程要点补充

    目录 四十五.尽量减少装箱拆箱 四十六.为应用程序创建专门的异常类 四十七.使用强异常安全保证 四十八.尽量使用安全的代码 四十九.实现与 CLS 兼容的程序集 五十.实现小尺寸.高内聚的程序集 这是 ...

  5. C/S结构 B/S结构

    [1]C/S 结构,即大家熟知的客户机和服务器结构.它是软件系统体系结构,通过它可以充分利用两端硬件环境的优势,将任务合理分配到Client端和Server端来实现,降低了系统的通讯开销.目前大多数应 ...

  6. /proc/meminfo中meminfo的计算方法

    /proc/meminfo里的可使用内存的计算没有那么简单,并不是简单的free和page cache的加和 free + pagecache 以此为基准 但是需要减去一些内存:首先要减去系统预留的内 ...

  7. ASP.NET MVC下使用文件上传和IIS7下的默认设置限制了上传大小的方法

    不多说了,直接用别人的 http://www.cnblogs.com/jiekzou/p/4491505.html

  8. Android SDK Manager下载,解决方案

    一.Windows 平台 在C:\Windows\System32\drivers\etc\hosts文件.添加一行:74.125.237.1       dl-ssl.google.com 二.Li ...

  9. CentOS 压缩(打包)和解压

    1.tar命令 -c 创建压缩文件 -x 解开压缩文件 -t 查看压缩包内有哪些文件 -z 用 Gzip压缩或解压 -j 用 bzip2压缩或解压 -v 显示压缩或解压的过程 -f 目标文件名,在 f ...

  10. JavaScript定义类的方式与其它OO语言有些差异

    JavaScript面向对象的程序编写与其它OO语言有一些出入,所以使用JavaScript的面向对象特性的时候,需要注意一些规范性的问题.下面就简单地谈一下,JavaScript如何定义一个类,在定 ...