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代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <deque>
  6. #include <vector>
  7. #include <queue>
  8. #include <string>
  9. #include <cstring>
  10. #include <map>
  11. #include <stack>
  12. #include <set>
  13. #include <cstdlib>
  14. #include <ctype.h>
  15. #include <numeric>
  16. #include <sstream>
  17. using namespace std;
  18. typedef long long LL;
  19. const double PI = 3.14159265358979323846264338327;
  20. const double E = 2.718281828459;
  21. const double eps = 1e-6;
  22. const int MAXN = 0x3f3f3f3f;
  23. const int MINN = 0xc0c0c0c0;
  24. const int maxn = 1e3 + 5;
  25. const int MOD = 1e9 + 7;
  26. int arr[maxn], dp[maxn];
  27. int main()
  28. {
  29. int n;
  30. while (cin >> n && n)
  31. {
  32. int i, j;
  33. for (i = 0; i < n; i++)
  34. scanf("%d", &arr[i]);
  35. memset(dp, 0, sizeof(dp));
  36. LL ans = 0;
  37. for (i = 0; i < n; i++)
  38. {
  39. dp[i] = arr[i];
  40. for (j = i - 1; j >= 0; j--)
  41. {
  42. if (arr[i] > arr[j])
  43. dp[i] = max(dp[i], dp[j] + arr[i]);
  44. }
  45. if (dp[i] > ans)
  46. ans = dp[i];
  47. }
  48. cout << ans << endl;
  49. }
  50. }

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. hdu 5078

    Osu! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Sub ...

  2. 从零开始开发一个vue组件打包并发布到npm (把vue组件打包成一个可以直接引用的js文件)

    自己写的组件 有的也挺好的,为了方便以后用自己再用或者给别人用,把组件打包发布到npm是最好不过了,本次打包支持 支持正常的组件调用方式,也支持Vue.use, 也可以直接引用打包好的js文件, 配合 ...

  3. js json ie不支持json

    JSON是包含在JScript 5.8中,而为了向下兼容ie8只有在文档模式是”Internet Explorer 8 Standards”的时候才使用JScripte 5.8,其他时候使用JScri ...

  4. Oracle 10gR2 RAC 启动与关闭

    一. 检查共享设备 一般情况下, 存放OCR 和 Voting Disk 的OCFS2 或者raw 都是自动启动的. 如果他们没有启动,RAC 肯定是启动不了的. 1.1 如果使用ocfs2的,检查o ...

  5. 好用的 Visual Studio插件

    Image Optimizer(图片优化)插件 使用行业标准优化任何JPEG,PNG和gif(包括动画gif).可以做有损和无损的优化.

  6. Python 日志模块的定制

    Python标准logging模块中主要分为四大块内容: Logger: 定义应用程序使用的接口 Handler: 将Loggers产生的日志输出到目的地 Filter: 对Loggers产生的日志进 ...

  7. 用jQuery实现简单的DOM操作

    通过jQuery创建元素节点:$oLi = $("<li></li>");这样我们就创建了一个li标签 如果想在元素节点中添加文本的话也挺简单:$oLi = ...

  8. word2007的配置进度怎么产生的?如何解决?

    那么要怎么解决这个问题呢?既然是安装的,那么我们便道安装控制器文件夹下面去找原因.在WIN8操作系统下,文件夹位于:C:\Program Files (x86)\Common Files\Micros ...

  9. android 反汇编一些资料

    Android软件安全与逆向分析   http://book.2cto.com/201212/12432.html Smali--Dalvik虚拟机指令语言 http://blog.csdn.net/ ...

  10. travelsal all files in a dir using recursion shell

    #!/bin/bash function getdir(){ ` do dir_or_file=$"/"$element if [ -d $dir_or_file ] then g ...