<span style="color:#000099;">/*
___________________________________________________________________________________________
author : Grant Yuan
time : 2014.7.18
algorithm : 最长上升子序列求和 ——————————————————————————————————————————————————————————————————————————————————————————— J - 简单dp 例题扩展
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
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
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<algorithm>
using namespace std; int a[100005],n;
int dp[100005]; int main()
{
while(1){
cin>>n;
if(n==0) break;
for(int i=1;i<=n;i++)
cin>>a[i]; memset(dp,0,sizeof(dp));
a[0]=0;
for(int i=1;i<=n;i++){
dp[i]=a[i];
for(int j=1;j<i;j++){
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+a[i]);}}
int max=dp[1];
for(int i=1;i<=n;i++)
if(dp[i]>max)
max=dp[i];
cout<<max<<endl;
}
return 0;
}
</span>

J Dp的更多相关文章

  1. 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) J dp 背包

    J. Bottles time limit per test 2 seconds memory limit per test 512 megabytes input standard input ou ...

  2. C. Multiplicity 简单数论+dp(dp[i][j]=dp[i-1][j-1]+dp[i-1][j] 前面序列要满足才能构成后面序列)+sort

    题意:给出n 个数 的序列 问 从n个数删去任意个数  删去的数后的序列b1 b2 b3 ......bk  k|bk 思路: 这种题目都有一个特性 就是取到bk 的时候 需要前面有个bk-1的序列前 ...

  3. Andrew Stankevich's Contest (21) J dp+组合数

    坑爹的,,组合数模板,,, 6132 njczy2010 1412 Accepted 5572 MS 50620 KB C++ 1844 B 2014-10-02 21:41:15 J - 2-3 T ...

  4. 牛客集训第七场J /// DP

    题目大意: 在矩阵(只有52种字符)中找出所有不包含重复字符的子矩阵个数 #include <bits/stdc++.h> #define ll long long using names ...

  5. hdu 4049 2011北京赛区网络赛J 状压dp ***

    cl少用在for循环里 #include<cstdio> #include<iostream> #include<algorithm> #include<cs ...

  6. 2017 ICPC区域赛(西安站)--- J题 LOL(DP)

    题目链接 problem description 5 friends play LOL together . Every one should BAN one character and PICK o ...

  7. codeforces gym 100947 J. Killing everything dp+二分

    J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standar ...

  8. icpc 2017北京 J题 Pangu and Stones 区间DP

    #1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...

  9. hdu 3689 杭州 10 现场 J - Infinite monkey theorem 概率dp kmp 难度:1

    J - Infinite monkey theorem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &am ...

随机推荐

  1. Unity学习笔记(二)——第一个Unity项目Hello Unity

    保留版权,转载请注明出处:http://blog.csdn.net/panjunbiao/article/details/9318811 在这一篇文章里,参照宣雨松的<Unity 3D游戏开发& ...

  2. 不知道的JavaScript

    你不知道的JavaScript上卷笔记 前言 You don't know JavaScript是github上一个系列文章  初看到这一标题的时候,感觉怎么老外也搞标题党,用这种冲突性比较强的题目吸 ...

  3. 基于CORS的geoserver同源访问策略

    这个问题理顺整个2天.终于攻克.记录下来. 1.下载文件 首先下载cors压缩包,解压,得到的是org/mortbay/servlets/CrossOriginFilter.class文件,把此文件拷 ...

  4. swift 简单语句 控制流语句

    在 Swift 中.有两种类型的语句:简单语句和控制流语句.简单语句是最常见的.用于构造表达式和声明.控制流语句则用于控制程序运行的流程,Swift 中有三种类型的控制流语句:循环语句.分支语句和控制 ...

  5. Spring3.0官网文档学习笔记(七)--3.4.2

    3.4.2 依赖与配置的细节     3.4.2.1  Straight values (primitives, Strings, and so on)     JavaBeans PropertyE ...

  6. Matlab spline

    请记住,,平稳 早期project图时,把富有弹性的细长木条(所谓样条)用压铁固定在样点上,在其它地方让它自由弯曲,然后沿木条画下曲线. 成为样条曲线 三次样条插值(简称Spline插值)是通过一系列 ...

  7. linux下登陆mysql失败

    一.提示由于没有密码,拒绝登陆 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) 1 ...

  8. 《Nginx文件类型错误解析漏洞--攻击演练》 (转)

    今天看书看到其中提到的一个漏洞,那就是Nginx+PHP的服务器中,如果PHP的配置里 cgi.fix_pathinfo=1 那么就会产生一个漏洞.这个配置默认是1的,设为0会导致很多MVC框架(如T ...

  9. java读写文件

    对于任何文件,不管有没有扩展名,都可以读写.切记,最后要.close();,否则效果出不来. 读操作: package com.wjy.read; import java.io.BufferedRea ...

  10. [置顶] Codeforces Round #197 (Div. 2)(完全)

    http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...