题目链接:

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): 47055    Accepted Submission(s): 21755

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
 
Author
lcy
分析:
普通的LIS问题,但是题目不是要求LIS序列的长度,而是LIS序列元素的值
改一下DP方程就ok
dp[0]=a[0]
dp[i]=max(dp[j]+a[i])  a[j]<a[i]且j<i
代码如下:
#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
if(n==)
break;
int a[n];
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int dp[n];
dp[]=a[];
for(int i=;i<n;i++)
{
int max_v=;
for(int j=;j<i;j++)
{
if(a[j]<a[i])
{
if(max_v<dp[j])
{
max_v=dp[j];
}
}
}
dp[i]=max_v+a[i];
}
int max_v=dp[];
for(int i=;i<n;i++)
{
if(max_v<dp[i])
{
max_v=dp[i];
}
}
printf("%d\n",max_v);
}
return ;
}

回来更新一下:

今天训练赛又遇到了这个题目

贴一下代码(比一开始精简了点,因为理解了)

#include<bits/stdc++.h>
using namespace std;
#define INF 99999
int main()
{
//最大递增子序列和
int n;
while(cin>>n,n)
{
int a[n];
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
int dp[n];
memset(dp,,sizeof(dp));
dp[]=a[];
int ans=;
for(int i=;i<n;i++)
{
int maxx=;
for(int j=;j<i;j++)
{
if(a[j]<a[i])
{
maxx=max(dp[j],maxx);
}
}
dp[i]=maxx+a[i];
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping

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

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

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

  3. HDU 1087 Super Jumping! Jumping! Jumping!(动态规划)

    Super Jumping! Jumping! Jumping! Problem Description Nowadays, a kind of chess game called “Super Ju ...

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

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

  5. 题解报告:hdu 1087 Super Jumping! Jumping! Jumping!

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

  6. HDU - 1087 Super Jumping!Jumping!Jumping!(dp求最长上升子序列的和)

    传送门:HDU_1087 题意:现在要玩一个跳棋类游戏,有棋盘和棋子.从棋子st开始,跳到棋子en结束.跳动棋子的规则是下一个落脚的棋子的号码必须要大于当前棋子的号码.st的号是所有棋子中最小的,en ...

  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! 最大递增子序列

    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. K先生

    每天多一点点的努力,不为别的,只为了日后能够多一些选择,选择云卷云舒的小日子,选择自己说了算的生活,选择自己喜欢的人. 加油,记K先生之名!

  2. OTSU算法学习 OTSU公式证明

    OTSU算法学习   OTSU公式证明 1 otsu的公式如下,如果当前阈值为t, w0 前景点所占比例 w1 = 1- w0 背景点所占比例 u0 = 前景灰度均值 u1 = 背景灰度均值 u = ...

  3. Ubuntu下卸载QT5.7.1再重装

    /**** 卸载QT5.7.1 *****/ .首先找到QT安装文件的位置,例如我的在/home/ttwang/software/qt5.7.1 .终端输入命令进入该目录,输入命令: ./Mainte ...

  4. 612.1.002 ALGS4 | Analysis of Algorithms

    我们生活在大数的时代 培养数量级的敏感! Tip:见招拆招 作为工程师,你先要能实现出来. 充实基础,没有什么不好意思 哪怕不完美.但是有时候完成比完美更重要. 之后再去想优化 P.S.作者Rober ...

  5. linux erlang环境安装

    1.安装环境:yum -y install make gcc gcc-c++ kernel-devel m4 glibc-devel autoconfyum -y install ncurses-de ...

  6. mysql 日期时间类型

    datetime timestamp year date time drop table test;create table test (dt datetime, ts timestamp, y ye ...

  7. OpenStreetMap、googleMap等经纬度和行列号之间相互转化(python,JavaScript,php,Java,C#等)

    python: # OpenStreetMap经纬度转行列号 def deg2num(lat_deg, lon_deg, zoom): lat_rad = math.radians(lat_deg) ...

  8. 单独配置 Ehcache

    package com.shy.ehcache; import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net ...

  9. docker如何创建支持SSH服务的镜像

    一般情况下,Linux系统管理员通过SSH服务来管理操作系统,但Docker的很多镜像是不带SSH服务的,那么我们怎样才能管理操作系统呢?在第一部分中我们介绍了一些进入容器的办法,比如用attach. ...

  10. mac 手动卸载软件位置

    系统偏爱设置 /Users/xxxxx/Library/Preferences/ xxxx 支持文件 /Users/xxxxx/Library/Application Support/xxx文件夹 数 ...