Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 40030    Accepted Submission(s): 18437

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

题目大意:就是有一种棋,从起点到终点有很多路径,从一个点跳x到另一个点b,如果b点的值(a[b])比b之前的某些点值大,那b的dp[b]就等于b+之前的某些点中max(dp[某些点之一]),然后求出最大的。有点像最大子串问题。

举几个例子就明白了

比如一组数为 1 2 3 4 1 2 3 4 5

那么  a[0]=1      a[1]=2    a[2]=3        a[3]=4        a[4]=1                                                      a[5]=2                                                                         a[6]=3       a[7]=4           a[8]=5

dp[0]=1  dp[1]=3    dp[2]=6       dp[4]=10     dp[4]=1(因为a[4]之前没有比他小的)        dp[5]=3(有个a[0]比它小,然后a[4]不能重复加)      dp[6]=6      dp[7]=10       dp[8]=15

然后 max=15

同理 另一组数  10 6 10 7 10 8 10 9 的max=31=6+7+8+10

然后奉上代码:

#include <iostream>
#include<math.h>
#include <iomanip>
#include<cstdio>
#include<string>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<stdlib.h>
#include<iterator>
#include<sstream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int n;
int a[];
int dp[];
while(cin>>n)
{
if(n==)
{
break;
}
for(int ii=;ii<n;ii++)
{
cin>>a[ii];//读数
}
dp[]=a[];//第一个数的最大和肯定就是第一个数
for(int i=;i<n;i++)
{
dp[i]=a[i];//将最初的dp[i]赋值为它本身
for(int j=;j<i;j++)//开始对i之前的数进行扫描
{
if(a[i]>a[j]&&a[i]+dp[j]>dp[i])
{//前一个条件是为了递增
//后一个条件是为了防止遇到小的就加,也保证dp[i]取到最大
dp[i]=a[i]+dp[j];
}
}
}
int max=dp[];
for(int i=;i<n;i++)
{
if(dp[i]>max)
{
max=dp[i];
}
}
cout<<max<<endl;
}
return ; }

这题 我开始没弄懂,还以为是找最子串,后来发现并不是。这算是第一题DP吧,还是参考了网上的代码的,希望之后能自己写。

杭电1087 Super Jumping! Jumping! Jumping!(初见DP)的更多相关文章

  1. Super Jumping! Jumping! Jumping!杭电1087

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

  2. 杭电OJ——1011 Starship Troopers(dfs + 树形dp)

    Starship Troopers Problem Description You, the leader of Starship Troopers, are sent to destroy a ba ...

  3. [2019杭电多校第一场][hdu6578]Blank(dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6578 计数问题想到dp不过分吧... dp[i][j][k][w]为第1-i位置中4个数最后一次出现的 ...

  4. HDU 1087 Super Jumping! Jumping! Jumping

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

  5. HDU 1087 Super Jumping! Jumping! Jumping!(求LSI序列元素的和,改一下LIS转移方程)

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

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

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

  7. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  8. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  9. 杭电acm阶段之理工大版

    想參加全国软件设计大赛C/C++语言组的同学,假设前一篇<C和指针课后练习题总结>没看完的,请先看完而且依照上面的训练做完,然后做以下的训练. 传送门:http://blog.csdn.n ...

随机推荐

  1. 广度优先搜索BFS---求出矩阵中“块”的个数

    题目: 给出一个 m x n 的矩阵,矩阵中的元素为0或1.如果矩阵中有若干个 1是相邻的,那么称这些1构成了一个“块”.求给定的矩阵中“块”的个数. 0 1 1 1 0 0 1 0 0 1 0 0 ...

  2. jQuery---$冲突的解决方案

    $冲突的解决方案 遇到其他js文件也用$包装了函数.可以把jQuery放在后面,并释放下$的控制权,也可以换个字符替代原来的$,例如$$ 或者,jQuery //jQuery释放$的控制权 $$ = ...

  3. Jenkins+robotframework持续集成环境(二)

    配置Jenkins上的robotframework环境 一.添加robot插件 需要导一个robot framework 的包,导包方式如下: 1.进入插件管理页面,选择“可选插件”,在右侧搜索栏搜索 ...

  4. sql多字段分组排序显示全部数据

    建表sql CREATE TABLE `tbl_demo` ( `id` ) COLLATE utf8_bin NOT NULL, `payer_name` ) COLLATE utf8_bin DE ...

  5. 使用css鼠标移动到图片放大效果

      <!DOCTYPE html>  <html>      <head>          <meta charset="UTF-8"& ...

  6. Spring IoC Container源码分析(二)-bean初始化流程

    准备 Person实例 @Data public class Person { private String name; private int age; } xml bean配置 <?xml ...

  7. 纪中5日T3 1566. 幸运锁(lucky.pas/c/cpp)

    1566. 幸运锁(lucky.pas/c/cpp) 题目描述 有一把幸运锁,打开它将会给你带来好运,但开锁时需要输入一个正整数(没有前导0).幸运锁有一种运算,对于一个正整数,返回他的相邻两位数字间 ...

  8. #4864. [BeiJing 2017 Wc]神秘物质 [FHQ Treap]

    这题其实挺简单的,有个东西可能稍微难维护了一点点.. \(merge\ x\ e\) 当前第 \(x\) 个原子和第 \(x+1\) 个原子合并,得到能量为 \(e\) 的新原子: \(insert\ ...

  9. 查看whl包名是否满足系统的条件的命令,以此解决whl包出现“is not a supported wheel on this platform”错误提示的问题

    在Ubuntu系统中,使用pip安装whl包时,常常会报如下错误: tensorflow_gpu-1.11.0-cp35-cp35m-manylinux1_x86_64.whl is not a su ...

  10. Flask之RESTFul API前后端分离

    Flask之RESTFul API前后端分离 一:虚拟环境搭建的两种方式 1 pipenv的使用 pip install --user pipenv安装pipenv在用户目录下 py -m site ...