<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. Graphical Shell with WebShell - WebOS Internals

    Graphical Shell with WebShell - WebOS Internals Graphical Shell with WebShell From WebOS Internals J ...

  2. dblink如果很慢可以用这种方式优化

    发现dblink如果很慢可以用这种方式加个/*+driving_site(xxx)*/,查询很快 DBLINK HINT /*+ driving_site(org) */ 优化策略和思路 使用DBLI ...

  3. tomcat 下部署 php

    由于需要测试一个PHP的环境.故记录此处. 环境 OS:win8.1 up1 64bit tomcat :8.0.14 64bit php:php-5.6.2-Win32-VC11-x64.zip 将 ...

  4. ORA-16047: DGID mismatch between destination setting and target database

    做DG的时候 主库两个节点无法把日志传到备库上 SQL> select dest_name,status,type,database_mode,protection_mode,destinati ...

  5. shell命令批量杀死MySQL连接进程

    (1)将全部的MySQL连接进程杀掉 for i in `mysql -uroot -pzhangyun -Bse "show processlist" | grep -v &qu ...

  6. Spark SQL 初步

    已经Spark Submit 2013哪里有介绍Spark SQL.就在很多人都介绍Catalyst查询优化框架.经过一年的发展后,.今年Spark Submit 2014在.Databricks放弃 ...

  7. C#-循环滚动字幕,timer,从左至右,从右至左,暂停---ShinePans

    Lable的Left属性是能够更改的,可是 Right属性不能够更改,所以我们能够利用 这个特点做自加 自减运算 using System; using System.Collections.Gene ...

  8. (017)将一棵二叉查找树重构成链表(keep it up)

    给定一棵二叉查找树,设计算法,将每一层的全部结点构建为一个 链表(也就是说, 假设树有D层,那么你将构建出D个链表). 这个题实质是个BFS,可是实现起来有点麻烦,又不像常见的BFS, 所以编写代码时 ...

  9. CSS计数器妙用

    做web的经常会遇到类似排行榜的需求, 特别是要求前n名的样式和后面人不一样. 通常大多数人对于这个需求的做法都是在后端处理好排名名次, 在前端填入内容, 然后针对前n名做特殊的样式处理. 但是这样有 ...

  10. DIV 居中对齐

    <div style="text-align:center;margin-right:auto;margin-left:auto">