Super Jumping! Jumping! Jumping! (最长上升子序列的和)
来源:互联网 发布:js动态显示隐藏div 编辑:程序博客网 时间:2024/05/16 10:17
问题 I: Super Jumping! Jumping! Jumping!
时间限制: 1 Sec 内存限制: 128 MB提交: 4 解决: 3
[提交][状态][讨论版]
题目描述
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 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.
输出
For each case, print the maximum according to rules, and one line one case.
样例输入
3 1 3 24 1 2 3 44 3 3 2 10
样例输出
4103
状态dp[i]表示以i结尾的递增子序列的和。
状态转移方程dp[i] = max(dp[j]) + a[i] | j < i 且 a[j] < a[i]
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <string>#include <algorithm>#include <cstdlib>using namespace std;const int maxn = 1000 + 10;int n;int a[maxn];int dp[maxn];int main(){ while (cin >> n, n){ for (int i = 1; i <= n; i++){ cin >> a[i]; } int sum = 0; for (int i = 1; i <= n; i++){ dp[i] = a[i]; for (int j = 1; j < i; j++){ if (a[j] < a[i]){ dp[i] = max(dp[i], dp[j] + a[i]); } } } int max1 = 0; for (int i = 1; i <= n; i++){ if (dp[i] > max1) max1 = dp[i]; } cout << max1 << endl; } return 0;}
0 0
- Super Jumping! Jumping! Jumping! (最长上升子序列的和)
- HDU 1087 Super Jumping! Jumping! Jumping!(dp最长上升子序列的和)
- hdu 1087 Super Jumping! Jumping! Jumping!(dp 最长上升子序列和)
- HDU 1087 Super Jumping! Jumping! Jumping! (最长上升子序列和)
- hdu1087 Super Jumping! Jumping! Jumping!(最长上升子序列和)
- HDU 1087 Super Jumping! Jumping! Jumping!最长上升子序列
- HDU1087 Super Jumping! Jumping! Jumping!【最长上升子序列+DP】
- HDU 1087 Super Jumping! Jumping! Jumping!(最大的上升子序列的和)(不是最长)(易混淆)
- hdoj--1087--Super Jumping! Jumping! Jumping!(最长上升序列)
- hduoj Super Jumping! Jumping! Jumping!【最大上升子序列和】
- hdu 1087 Super Jumping! Jumping! Jumping!-dp 最长上升子序列和
- HDU 1080-Super Jumping! Jumping! Jumping!(LIS最长上升子序列-最大递增子段和)
- hdu 1087 Super Jumping! Jumping! Jumping! 最长上升子序列的变形
- Super Jumping! Jumping! Jumping! (最长子序列)
- hdu 1087 Super Jumping! Jumping! Jumping!(最长上升子序列变形)
- (hdu step 3.2.3)Super Jumping! Jumping! Jumping!(DP:求最长上升子序列的最大和)
- hdu 1087 Super Jumping! Jumping! Jumping!(LIS变形题,求上升子序列的最大和)
- HDU 1087 Super Jumping!Jumping!Jumping求连续上升子序列的最大和值 (解析)
- poj-4118-OpenJ_Bailian-开餐馆【贪心】【背包】
- VS2015使用技巧 dll之新建类库,添加类库至现有项目,实例化类库中的类
- KMP算法小结
- android下数据库的创建
- google play service lib 最新android版本库下载地址
- Super Jumping! Jumping! Jumping! (最长上升子序列的和)
- 如何理解和熟练运用js中的call及apply?
- 最大子串和
- 写一个简单的输入框
- 广告增加跳过的较好用户体验
- 数据适配器---BaseAdapter
- 用联合测试大小端
- POJ_1787_Charlie'sChange(多重背包&&记录路径)
- 随堂笔记7.30:数组,四种排序方法-------1