【HDU - 1087】Super Jumping! Jumping! Jumping! (最大上升子序列类问题,dp)

题干:

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

解题报告:

     就是个最大递增子序列。

附一个别人的解题报告:

      求最大的递增子序列的和,不用连续,例如(1,5,2),那么(1,2)也算他的递增子序列。 

  我刚开始做了一遍,忽略了不用连续这个问题,结果发现好简单,提交就是不对,应当注意这里。

  这个还是得用动态规划去做,最后的最优结果是由上一步的结果加上上一次的决策。n个数,由n-1个数的结果加上第n个数。n-1个数由n-2个数的结果。。。。。

  推倒最后,前两个数的的结果就很容易求了.以数列(3,2,4,2,3,6)为例。原博客

 

  

下标i012345
a[i]324236
sum[i]3272513
ans0377513

  

 

 

 

 

AC代码:

//dp需要赋初值!
#include<bits/stdc++.h>using namespace std;
int n;
int a[1000 + 5];
int dp[1000 + 5];
int main()
{while(~scanf("%d",&n)) {if(n == 0) break;memset(dp,0,sizeof(dp));for(int i = 1; i<=n; i++) scanf("%d",&a[i]);for(int i = 1; i<=n; i++) dp[i] = a[i];for(int i = 1; i<=n; i++) {for(int j = 1; j<i; j++) {if(a[i] > a[j] )dp[i] = max(dp[j] + a[i],dp[i] );}}printf("%d\n",*max_element(dp+1,dp+n+1));}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441886.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

oracle启动监听读取哪个文件,监听服务启动及数据文件恢复oracle数据库

最近遭遇了 oralce 监听服务启动了 又自行关闭的 悲惨经历我把我的过程和大家分享一下&#xff01;1)排查原因程序员是懒惰的&#xff0c;我始终都希望能够成功启动监听服务&#xff0c;但是就是事与愿违有一下方式可能不能成功启动监听1.端口占用&#xff0c;oralce 要用到152…

linux串口写入命令失败,linux – 从串口读取失败

我有以下C程序&#xff1a;#include #include #include int main(){int fd open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_NONBLOCK);if(fd < 0){perror("Could not open device");}printf("Device opened\n");struct termios options;tcgetattr…

【HDU - 1172】猜数字 (枚举暴力)

题干&#xff1a; 猜数字游戏是gameboy最喜欢的游戏之一。游戏的规则是这样的&#xff1a;计算机随机产生一个四位数&#xff0c;然后玩家猜这个四位数是什么。每猜一个数&#xff0c;计算机都会告诉玩家猜对几个数字&#xff0c;其中有几个数字在正确的位置上。 比如计算机随…

linux内核支持的加密算法,Linux Kernel(Android) 加密算法总结(三)-应用程序调用内核加密算法接口...

本文将主要介绍&#xff0c;如何在应用程序空间中(user space) 调用内核空间(kernel space)加密模块提供的加密算法API。方法一&#xff1a;通过调用crypto: af_alg - User-space interface for Crypto API&#xff0c; Herbert Xu 2010年&#xff0c;给内核2.6.X 接口实现下面…

【HDU - 2571】 命运(记忆化搜索)

题干&#xff1a; 穿过幽谷意味着离大魔王lemon已经无限接近了&#xff01; 可谁能想到&#xff0c;yifenfei在斩杀了一些虾兵蟹将后&#xff0c;却再次面临命运大迷宫的考验&#xff0c;这是魔王lemon设下的又一个机关。要知道&#xff0c;不论何人&#xff0c;若在迷宫中被…

【HDU - 2089 】不要62 (dp)

题干&#xff1a; 杭州人称那些傻乎乎粘嗒嗒的人为62&#xff08;音&#xff1a;laoer&#xff09;。 杭州交通管理局经常会扩充一些的士车牌照&#xff0c;新近出来一个好消息&#xff0c;以后上牌照&#xff0c;不再含有不吉利的数字了&#xff0c;这样一来&#xff0c;就可…

nmon监控linux内存,使用Nmon监控Linux系统性能

Nmon (又称 Nigel’s Monitor) 是一款常用的系统性能监视工具&#xff0c;由 IBM 工程师 Nigel Griffiths 开发&#xff0c;适用于 AIX 和 Linux 操作系统。该工具可以直接在屏幕上显示当前操作系统的资源利用率&#xff0c;以帮助大家找出系统瓶颈和协助系统调优。由于其十分出…

【Codeforces - 632C】The Smallest String Concatenation (对string巧妙排序)

题干&#xff1a; Youre given a list of n strings a1, a2, ..., an. Youd like to concatenate them together in some order such that the resulting string would be lexicographically smallest. Given the list of strings, output the lexicographically smallest…

linux mysql授权远程登录,Linux中 MySQL 授权远程连接的方法步骤

说明&#xff1a;当别的机子(IP )通过客户端的方式在没有授权的情况下是无法连接 MySQL 数据库的&#xff0c;如果需要远程连接 Linux 系统上的 MySQL 时&#xff0c;必须为其 IP 和 具体用户 进行 授权 。一般 root 用户不会提供给开发者。如&#xff1a;使用 Windows 上的 SQ…

【HDU - 3466 】Proud Merchants(dp,背包问题,巧妙排序)

题干&#xff1a; Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more…

linux 双通道 磁盘,HP MSA2012SA 双通道 磁盘阵列配置说明 for linuxoracle

HP MSA2012SA磁盘阵列配置说明说明&#xff1a;可以先安装HP服务器的操作系统&#xff0c;等安装完了以后再配置磁阵&#xff1b;1、安装好服务器的操作系统&#xff1b;该安装的包都安装上&#xff1b;2、磁盘阵列上架&#xff0c;加电&#xff0c;SAS线不用接服务器&#xff…

linux mariadb 乱码,MariaDB插入中文数据乱码解决过程

基本情况&#xff1a;MariaDB安装方式&#xff1a;yum乱码解决过程&#xff1a;1.查看当前数据库编码(登录数据库后)# show variables like character%;(上图为已经配置成功)2.如果结果不为上图则需要设置数据库配置文件•编辑 /etc/my.cnf.d/client.cnf 文件&#xff0c;添加如…

【nyoj - 890】 分东西 (水题 二进制)

题干&#xff1a; 分东西 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB 难度&#xff1a;1 输入 第一行输出一个数i表示有i组情况&#xff08;0<i<10&#xff09; 接下来的i行&#xff0c;每一行输入两个个数M(0<M<1000000)和N(0<N<2…

摩托罗拉为什么要限制自家linux手机,摩托罗拉为何在安卓手机大放异彩的时候,突然开始衰败了呢?...

摩托罗拉从一开始就走在了安卓的道路上&#xff0c;并且魅力四射&#xff0c;可以说一时间也是风光无比。对比诺基亚坚定的走向WP之路&#xff0c;这一点摩托罗拉没有走错。安卓当时的热门机中&#xff0c;摩托罗拉的里程碑系列可以算作是经典之作。销量也可以进入当年的前三。…

【POJ - 3624 】Charm Bracelet (dp,0-1背包裸题)

题干&#xff1a; Bessie has gone to the malls jewelry store and spies a charm bracelet. Of course, shed like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a weight Wi (1 ≤ Wi…

pta输出三角形字符阵列c语言,C语言l|博客园作业11

这个作业属于哪个课程C语言程序设计II这个作业要求在哪里链接我在这个课程的目标是掌握C语言以及熟练运用这个作业在哪个具体方面帮助我实现目标询问同学&#xff0c;百度&#xff0c;vs2019上的报错参考文献链接1.1 题目名6-1 统计某类完全平方数本题要求实现一个函数&#xf…

【nyoj - 252】 01串(简单dp)

题干&#xff1a; 01串 时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB 难度&#xff1a;2 输入 第一行有一个整数n&#xff08;0<n<100&#xff09;,表示有n组测试数据; 随后有n行&#xff0c;每行有一个整数m(2<m<40)&#xff0c;表示01串的…

c语言乘法表 m*(9-i),C语言做九九乘法表.doc

C语言做九九乘法表#include void main(){int i,j,x;/*第一种*/printf("第一种&#xff1a;\n");for(i1;i<9;i){for(ji;j>1;j--){printf("%d*%d%d\t",i,j,i*j);}printf("\n");}/*第二种*/printf("第二种&#xff1a;\n");for(i9;…

*由易到难的讲解动态规划(精)

简介(入门) 什么是动态规划&#xff0c;我们要如何描述它? 动态规划算法通常基于一个递推公式及一个或多个初始状态。 当前子问题的解将由上一次子问题的解推出。使用动态规划来解题只需要多项式时间复杂度&#xff0c; 因此它比回溯法、暴力法等要快许多。 现在让我们通过一…

计划的主体部分应有哪些内容_本科论文查重查哪些部分内容?需要注意什么?...

作者&#xff1a;新风学术网关于本科毕业论文查重是查重哪些首先我们需要了解的是查重的依据&#xff0c;论文查重是建立在论文上的&#xff0c;我们先要知道一篇论文有哪些地方能用来检测&#xff0c;一篇论文它的组成是由封面、目录、前言、正文、参考文献、附录、页眉页脚等…