题意:

给定n个数的序列, 找出最长上升子序列和。

分析:

#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define _rep(i,a,b) for(int i = a; i <= b; i++)
using namespace std;
const int inf = 1e9 + ;
int a[ + ], dp[ + ], n;
int main()
{
// freopen("1.txt", "r", stdin);
while(cin >> n && n){
memset(dp, , sizeof(dp));//dp数组含义是以i为结束的最长上升子序列的最大值
rep(i,,n){
cin >> a[i];dp[i] = a[i];
}
int ans = -inf;
rep(i,,n){
rep(j, ,i){
if(a[i] > a[j]){
dp[i] = max(dp[i] , dp[j] + a[i]);//这里的最大值, 要么就是原来dp[j]的值加上a[i]
//要么就是dp[i]本身(dp[j]只有加上a[i]才能转移到dp[i])
}
ans = max(ans, dp[i]); }
} // rep(i,0,n) ans = max(ans, dp[i]); //其实这里没必要, dp[i]每次更新后都是最优
printf("%d\n", ans);
}
}

HDU 1087 Super Jumping! Jumping! Jumping! (LIS的最大和)的更多相关文章

  1. HDU 1087 Super Jumping! Jumping! Jumping

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

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

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

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

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

  4. HDU 1087 Super Jumping! Jumping! Jumping! 最长递增子序列(求可能的递增序列的和的最大值) *

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

  5. HDU 1087 Super Jumping! Jumping! Jumping! (DP+LIS)

    题意:给定一个长度为n的序列,让你求一个和最大递增序列. 析:一看,是不是很像LIS啊,这基本就是一样的,只不过改一下而已,d(i)表示前i个数中,最大的和并且是递增的, 如果 d(j) + a[i] ...

  6. HDU 1087 Super Jumping! Jumping! Jumping! ——(LIS变形)

    和之前那个长方体最大高度是换汤不换药的题目.每次找之前最大的一个能接的接上即可.代码如下: #include <stdio.h> #include <algorithm> #i ...

  7. hdu 1087 Super Jumping! Jumping! Jumping!(最大上升子序列和)

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

  8. 题解报告:hdu 1087 Super Jumping! Jumping! Jumping!

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

  9. hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 ------------------------------------------------ ...

随机推荐

  1. NowCoder数列

    题目:https://www.nowcoder.com/questionTerminal/0984adf1f55a4ba18dade28f1ab15003 #include <iostream& ...

  2. 在MacOs上安装sqlsrv Mojave - 找不到'php.h'文件

    Mojave没有安装标头. 要安装标头: open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_1 ...

  3. bzoj 4859 [BeiJing2017]机动训练

    题面 https://www.lydsy.com/JudgeOnline/problem.php?id=4859 题解 和管道取珠类似 首先把平方转化成两条路径经过的图案相同的方案数 对于一条路径 方 ...

  4. Hdu 4778 Gems Fight! (状态压缩 + DP)

    题目链接: Hdu 4778 Gems Fight! 题目描述: 就是有G种颜色,B个背包,每个背包有n个宝石,颜色分别为c1,c2............两个人轮流取背包放到公共容器里面,容器里面有 ...

  5. POM报错Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from

    解决方式一:   1.查看.m2\repository\org\apache\maven\plugins\maven-resources-plugin\下maven-resources-plugin- ...

  6. TNS-12508 When Issuing Any SET Command For The Listene

    TNS-12508 When Issuing Any SET Command For The Listener fact: Oracle Net Services    fact: TNS Liste ...

  7. DNS正、反向解析+负载均衡+智能DNS+密钥认证

    主机名 IP 软件包 系统版本 内核版本 实验环境 master 192.168.30.130 bind.x86_64 32:9.8.2-0.17.rc1.el6_4.6 bind-chroot.x8 ...

  8. Hadoop工作流不足(六)

    不多说,直接上干货! 为此,需要第三方框架.如Azkaban或Oozie! Azkaban https://azkaban.github.io/ 具体,见我的博客,Azkaban概念学习系列.http ...

  9. [ HEOI 2016 ] 树

    \(\\\) Description 给出一颗树,开始只有 \(1\) 号节点有标记. \(\ C\ x\) 对 \(x\) 号节点打标记 \(\ Q\ x\) 查询 \(x\) 号节点深度最深的有标 ...

  10. Web前端开发的四个阶段(小白必看)

    第一阶段:HTML的学习 超文本标记语言(HyperText Mark-up Language 简称HTML)是一个网页的骨架,无论是静态网页还是动态网页,最终返回到浏览器端的都是HTML代码,浏览器 ...