A - Super Jumping! Jumping! Jumping!

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.

InputInput 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.
OutputFor each case, print the maximum according to rules, and one line one case.
Sample Input

  1. 3 1 3 2
  2. 4 1 2 3 4
  3. 4 3 3 2 1
  4. 0

Sample Output

  1. 4
  2. 10
  3. 3
  1.  题目大意:求升序子序列的最大和
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int dp[];//dp用于存放从数组头到此为止的最大升序子序列和
  5. int n, a[];
  6. int maxn;
  7.  
  8. int main(){
  9. while(~scanf("%d", &n) && n){
  10. maxn = ;
  11. for(int i=; i<n; i++){
  12. scanf("%d", a+i);
  13. dp[i] = a[i];//将每个ai的值赋予dpi
  14. }
  15. for(int i=; i<n; i++){
  16. for(int j=; j<i; j++){
  17. if(a[i] > a[j] && dp[i] < dp[j]+a[i])
  18. dp[i] = dp[j] + a[i];
  19. if(dp[i] > maxn) maxn = dp[i];
  20. }
  21. }
  22.  
  23. printf("%d\n",maxn);
  24. }
  25. }

是今天刚学的dp,告诉我们这类题目没有固定的模板,更重要的是思维和思考,借助dp这样的一个数组,去存放你需要求或相关的变量。既然没有固定模板,则需要更多的练习,去接触更多样式的巧妙的题目

dp --A - Super Jumping! Jumping! Jumping!的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. Super Jumping! Jumping! Jumping!(dp)

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

  7. HDU1087:Super Jumping! Jumping! Jumping!(DP)

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

  8. 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)

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

随机推荐

  1. 七、Application类

    前言:每个运行的WPF应用程序都由System.Windows.Application类的一个实例来表示.程序集资源(assemblyre sources)的每个资源是一块可嵌入到编译过得应用程序中的 ...

  2. 如何写出优雅的Python代码?

    有时候你会看到很Cool的Python代码,你惊讶于它的简洁,它的优雅,你不由自主地赞叹:竟然还能这样写.其实,这些优雅的代码都要归功于Python的特性,只要你能掌握这些Pythonic的技巧,你一 ...

  3. Codeforces_729_C

    http://codeforces.com/problemset/problem/729/C 二分找最小容量,然后找符合的最小花费. #include<iostream> #include ...

  4. mybaits分页插件的使用

    1.导入依赖坐标 <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>p ...

  5. AppBox实战: 如何实现一对多表单的增删改查

      本篇通过完整示例介绍如何实现一对多关系表单的相应服务及视图. 一.准备数据结构   示例所采用的数据结构为"物资需求"一对多"物资清单",通过IDE的实体设 ...

  6. mapreduce清洗数据

    继上篇 MapReduce清洗数据 package mapreduce; import java.io.IOException; import org.apache.hadoop.conf.Confi ...

  7. DOCKER绝对领域从2048到4069?不:25519,数字的飞跃,HTTP/2

    这个标题花了几分钟,远远超过我构思以下内容的时间损耗,希望大家且看且珍惜,因为这是为数不多的cnblog特别标题 我记得很久以前,我开了一系列随笔,从第一篇揭发233的docker/machine开始 ...

  8. 使用sass语法生成自己的css的样式库

    前言 先说一下 sass 和 scss的区别 sass 是一种缩进语法(即没有花括号和分号,只使用换行 缩进的方式去区别子元素,PS:这是我个人的理解) scss 是css-like语法  (它的语法 ...

  9. 安装Debian的磨磨唧唧

    安装Debian的磨磨唧唧 唆使VMware罢工的微软 这两天心血来潮想折腾,拆了我亲爱的Ubuntu.装个Debian 不过因为加入了微软的insider版本 就很尴尬的发现当我打开我的VMware ...

  10. zabbix流量过大就断图

    监控内网千兆交换机,流量图断断续续,大概位于400-500兆就会断图,而且还不准. 按照这个操作几乎可以成功 链接:http://itfish.net/article/23536.html     h ...