HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】

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

Total Submission(s): 44670 Accepted Submission(s): 20693

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

题意

寻找最长上升子序列,输出其和

思路

如果一个数组的最后一个元素大于前面的某一个元素,那么这个数组的最长上升子序列和就等于前面的那一个元素到开头组成的数组的最长上升子序列和 + 这个数组元素的值

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std; typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e3 + 5;
const int MOD = 1e9 + 7;
int arr[maxn], dp[maxn]; int main()
{
int n;
while (cin >> n && n)
{
int i, j;
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
memset(dp, 0, sizeof(dp));
LL ans = 0;
for (i = 0; i < n; i++)
{
dp[i] = arr[i];
for (j = i - 1; j >= 0; j--)
{
if (arr[i] > arr[j])
dp[i] = max(dp[i], dp[j] + arr[i]);
}
if (dp[i] > ans)
ans = dp[i];
}
cout << ans << endl;
}
}

HDOJ_1087_Super Jumping! Jumping! Jumping! 【DP】的更多相关文章

  1. Kattis - honey【DP】

    Kattis - honey[DP] 题意 有一只蜜蜂,在它的蜂房当中,蜂房是正六边形的,然后它要出去,但是它只能走N步,第N步的时候要回到起点,给出N, 求方案总数 思路 用DP 因为N == 14 ...

  2. HDOJ 1423 Greatest Common Increasing Subsequence 【DP】【最长公共上升子序列】

    HDOJ 1423 Greatest Common Increasing Subsequence [DP][最长公共上升子序列] Time Limit: 2000/1000 MS (Java/Othe ...

  3. HDOJ 1501 Zipper 【DP】【DFS+剪枝】

    HDOJ 1501 Zipper [DP][DFS+剪枝] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...

  4. HDOJ 1257 最少拦截系统 【DP】

    HDOJ 1257 最少拦截系统 [DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  5. HDOJ 1159 Common Subsequence【DP】

    HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...

  6. POJ_2533 Longest Ordered Subsequence【DP】【最长上升子序列】

    POJ_2533 Longest Ordered Subsequence[DP][最长递增子序列] Longest Ordered Subsequence Time Limit: 2000MS Mem ...

  7. HackerRank - common-child【DP】

    HackerRank - common-child[DP] 题意 给出两串长度相等的字符串,找出他们的最长公共子序列e 思路 字符串版的LCS AC代码 #include <iostream&g ...

  8. LeetCode:零钱兑换【322】【DP】

    LeetCode:零钱兑换[322][DP] 题目描述 给定不同面额的硬币 coins 和一个总金额 amount.编写一个函数来计算可以凑成总金额所需的最少的硬币个数.如果没有任何一种硬币组合能组成 ...

  9. LeetCode:完全平方数【279】【DP】

    LeetCode:完全平方数[279][DP] 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数的个数最少. 示 ...

随机推荐

  1. MySQL防止重复插入唯一限制的数据 4种方法

    MySQL防止重复插入唯一限制的数据,下面我们逐一分析 : 1.insert ignore into 当插入数据时,如出现错误时,如重复数据,将不返回错误,只以警告形式返回.所以使用ignore请确保 ...

  2. Openstack(Kilo)安装系列之glance(六)

    安装配置 Before you install and configure the Image service, you must create a database, service credent ...

  3. NDK版本 下载地址

    最新版本r16 https://dl.google.com/android/repository/android-ndk-r16-windows-x86.zip https://dl.google.c ...

  4. trait优先级 与 使用

    之前一直沒有讲到trait,在此我不得不提一下trait中的优先级: 在trait继承中,优先顺序依次是:来自当前类的成员覆盖了 trait 的方法,而 trait 则覆盖了被继承的方法. For e ...

  5. python update from 2.6 to 2.7

    1 .wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 2.tar -jxvf Python-2.7.3.tar.bz2 &am ...

  6. 【MVC model 验证失效 】【Unexpected token u in JSON at position 0】【jquery-plugin-validation】

    问题描述:mvc model 调用jquery-plugin-validation 实现 前台的数据验证,时报错 Unexpected token u in JSON at position 0 很讨 ...

  7. boost::bind 详解

    使用 boost::bind是标准库函数std::bind1st和std::bind2nd的一种泛化形式.其可以支持函数对象.函数.函数指针.成员函数指针,并且绑定任意参数到某个指定值上或者将输入参数 ...

  8. css生成三角形

     转载:http://www.cnblogs.com/lhb25/p/css-and-css3-triangle.html Triangle Up    1 2 3 4 5 6 7 #triangle ...

  9. SpringBoot专题1----springboot与mybatis的完美融合

    springboot大家都知道了,搭建一个spring框架只需要秒秒钟.下面给大家介绍一下springboot与mybatis的完美融合: 首先:创建一个名为springboot-mybatis的ma ...

  10. 史上最易懂的大数据 OTO

    史上最易懂的大数据 OTO http://network.51cto.com/art/201503/467068.htm 终于有人把O2O.C2C.B2B.B2C的区别讲透了 http://tech. ...