当前位置: 首页 > news >正文

HDU-1087-Super Jumping! Jumping! Jumping!(DP+上升子序列)

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


题意:跳棋规则:只能往右跳到分数比现在高的地方,求最大得分。找上升子序列的和为最大的子序列。


 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 
 6 int a[1005];
 7 int dp[1005];
 8 int n;
 9 
10 int main(){
11     while(scanf("%d",&n)&&n){
12         memset(a,0,sizeof(a));
13         
14         for(int i=1;i<=n;i++){
15             scanf("%d",&a[i]);
16             dp[i]=a[i];
17         }
18     
19         for(int i=1;i<=n;i++){
20             for(int j=1;j<=i;j++){
21                 if(a[i]>a[j]) dp[i]=max(dp[i],dp[j]+a[i]);
22             }
23         } 
24         int ans=0;
25         for(int i=1;i<=n;i++){
26             if(ans<dp[i]) ans=dp[i];
27         }
28         printf("%d\n",ans);            
29     }
30     
31     return 0;
32 } 

 


 

转载于:https://www.cnblogs.com/yzhhh/p/10079607.html

相关文章:

  • 比特币代码分析7 交易校验
  • rsync + inotify 数据实时同步
  • JQuery each循环跳出和结束
  • 从paxos到zookeeper 分布式一致性原理与实践
  • 「CH2101」可达性统计 解题报告
  • java websocket学习
  • 1600802047 android 第三次作业(音乐播放器)
  • bzoj 2555 SubString——后缀自动机+LCT
  • BZOJ3238 [Ahoi2013]差异
  • 使用Java代码自定义Ribbon配置
  • CephFS 文件系统应用
  • 第二冲刺阶段第十三天
  • 近似推断---期望传播
  • 联合国儿童基金会投资六家区块链初创企业,目标是解决“全球性挑战”
  • MaxCompute新功能发布
  • Google 是如何开发 Web 框架的
  • JavaScript-如何实现克隆(clone)函数
  • [译]Python中的类属性与实例属性的区别
  • CentOS7 安装JDK
  • Codepen 每日精选(2018-3-25)
  • CSS选择器——伪元素选择器之处理父元素高度及外边距溢出
  • Date型的使用
  • echarts的各种常用效果展示
  • Java 实战开发之spring、logback配置及chrome开发神器(六)
  • JavaScript DOM 10 - 滚动
  • Java教程_软件开发基础
  • java小心机(3)| 浅析finalize()
  • mysql 5.6 原生Online DDL解析
  • React as a UI Runtime(五、列表)
  • sublime配置文件
  • Vue--数据传输
  • 飞驰在Mesos的涡轮引擎上
  • 浮动相关
  • 扩展资源服务器解决oauth2 性能瓶颈
  • 整理一些计算机基础知识!
  • ​LeetCode解法汇总518. 零钱兑换 II
  • # C++之functional库用法整理
  • #etcd#安装时出错
  • #LLM入门|Prompt#1.8_聊天机器人_Chatbot
  • #我与Java虚拟机的故事#连载02:“小蓝”陪伴的日日夜夜
  • %3cscript放入php,跟bWAPP学WEB安全(PHP代码)--XSS跨站脚本攻击
  • (1)(1.11) SiK Radio v2(一)
  • (14)目标检测_SSD训练代码基于pytorch搭建代码
  • (附源码)ssm航空客运订票系统 毕业设计 141612
  • (六) ES6 新特性 —— 迭代器(iterator)
  • (四)Controller接口控制器详解(三)
  • (转载)虚幻引擎3--【UnrealScript教程】章节一:20.location和rotation
  • .NET : 在VS2008中计算代码度量值
  • .net Application的目录
  • .NET 简介:跨平台、开源、高性能的开发平台
  • .NET 使用 XPath 来读写 XML 文件
  • .NET8.0 AOT 经验分享 FreeSql/FreeRedis/FreeScheduler 均已通过测试
  • .NET下的多线程编程—1-线程机制概述
  • ::before和::after 常见的用法
  • @private @protected @public