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. 使用jmeter实现对jar包的调用

    一.前言 在我们测试接口的过程中,可能有时需要用到第三方jar包来生成一些测试数据(如有时需要对参数的输入值使用第三方jar包进行加密操作),涉及到这种的情况,普遍做法是:手动调用jar包获得需要的值 ...

  2. 安装python各类工具包、IDE以及著名开源模块如kaldi等的简单总结

    在学习一门语言或者使用一个著名的开源工具时,搭建环境是非常重要的一步,在环境搭建的过程中往往要踩很多坑.昨天一不小心把电脑操作系统整坏了,搞了个通宵算是搞定了,把win10系统重装回win7,但之前搭 ...

  3. Python之Matplotlib库常用函数大全(含注释)

    plt.savefig(‘test’, dpi = 600) :将绘制的图画保存成png格式,命名为 test plt.ylabel(‘Grade’) :  y轴的名称 plt.axis([-1, 1 ...

  4. 更改MVC注册Areas的顺序,掌控Areas的运作

    [转自:http://www.cnblogs.com/dozer/archive/2010/04/14/change-order-of-MVC-Areas.html] 一.前言 首先,有人要问,为什么 ...

  5. LBP纹理特征

    LBP-Local Binary Pattern,局部二值模式. 灰度不变性 改进:圆形LBP.旋转不变性 MB-LBP特征,多尺度Multiscale Block LBP: [转载自] 目标检测的图 ...

  6. Windows防火墙端口规则设置新建方法

    from:https://jingyan.baidu.com/article/2a1383289fd094074a134ff0.html Windows防火墙有什么用呢?它是电脑的一道安全屏障,可以有 ...

  7. Delphi 中窗口文件与无窗口Pas文件的区别 (MTM)

    implementation {$R *.dfm}  ---- 带窗口的 dfm -- 一般的 windows 窗口 {$R *.fmx}  ---- 带窗口的 fmx -- 一般的 FireMonk ...

  8. linux的ssh命令

    转自:http://man.linuxde.net/ssh ssh命令 网络安全 ssh命令是openssh套件中的客户端连接工具,可以给予ssh加密协议实现安全的远程登录服务器. 语法 ssh(选项 ...

  9. java的list去重

    Set<EmployeeInfoDTO> empSet = new HashSet<EmployeeInfoDTO>(empListAll);List<EmployeeI ...

  10. ZOJ 3661 Palindromic Substring(回文树)

    Palindromic Substring Time Limit: 10 Seconds      Memory Limit: 65536 KB In the kingdom of string, p ...