HDU 1087 解题报告
来源:互联网 发布:淘宝买家注册时间查询 编辑:程序博客网 时间:2024/06/01 17:32
Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23005 Accepted Submission(s): 10122
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.
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.
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 24 1 2 3 44 3 3 2 10
Sample Output
4103分析:题意是要求出单调递增序列的最大和。
类似于HDU1003题,考虑这个单调序列的结束位置(参见 HDU 1003 解题报告)。如果在当前位置结束,那个这个以当前位置结束的单调增序列的最大和必然是当前值或者是以当前位置之前的某个位置结束的最大和加上当前值,当然这种情况必须符合条件是当前位置的值比那个序列的结束值要大。
步骤:首先,读取数组的值,把当前值赋给当前结束位置的最大值。然后2层循环,内存循环对应上面说的当前位置,这样结束后即可得到以每个位置结束的单调增序列的最大和。
代码:#include<stdio.h>int value[1002], sum[1002];int getMax(int a, int b){if(a>b){return a;}return b;}int main(){int n, max;while(scanf("%d", &n), n){for(int i=0; i<n; i++){scanf("%d", &value[i]);sum[i] = value[i];}max = value[0];for(int i=0; i<n-1; i++){for(int j=i+1; j<n; j++){if(value[j]>value[i]){sum[j] = getMax(sum[j], sum[i]+value[j]);max = getMax(max, sum[j]);}}}printf("%d\n", max);}}
0 0
- HDU 1087 解题报告
- HDU 3342 解题报告
- HDU 3336 解题报告
- HDU 3335 解题报告
- hdu 2516解题报告
- hdu 1004解题报告
- hdu 2139解题报告
- hdu 1019解题报告
- hdu 1064 解题报告
- HDU 1113 解题报告
- hdu 1068 解题报告
- HDU:2050解题报告
- hdu 4001解题报告
- hdu 1005解题报告
- HDU解题报告--1003
- HDU解题报告--1004
- HDU解题报告--1005
- HDU 1005 解题报告
- Git for windows 的使用介绍
- Android 优化 编程 规范
- 【基础算法】排序-复杂排序之二(快速排序)
- Mac OS X的[内存]:wired, active, inactive和free
- UVALive 6525 Attacking rooks 二分匹配 经典题
- HDU 1087 解题报告
- cocos2dx中关于Action动作的相关API的详细介绍
- 菜鸟装apache,PHP及扩展
- Round-up of 30 AJAX Tutorials
- LINQ to Entities: Combining Predicates(组合判断)
- ./configure 参数解析
- 认知障碍的悲催错误
- Android-2电话应用,短信应用
- hdu1711