hdu1087
2015-11-07 21:20
429 查看
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
Sample Output
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
#include<iostream>//简单的最长上升子序列动态规划求和 #include<algorithm> using namespace std; int main() { int n; while(cin>>n&&n!=0) { int j,a[1024],i,dp[1024]; for(i=0;i<n;i++) { cin>>a[i]; } dp[0]=a[0]; for(i=1;i<n;i++) { dp[i]=a[i]; for(j=0;j<=i;j++)//dp的值表示到j为止的最长上升子序列之和 { if(a[i]>a[j])//选择机制要不要加进来 { if(dp[j]+a[i]>dp[i]) { dp[i]=dp[j]+a[i]; } } } } sort(dp,dp+n); cout<<dp[n-1]<<endl; } return 0; }
相关文章推荐
- Apple ID设置教程指南
- Apple ID设置教程指南
- c++模板函数
- Linux中的进程关系详解
- acmicpc-asia-tokyo-regional-contestC-Shopping(贪心)
- 关于java单例模式getInstance()
- Maven之——编译文件的编码设置
- GDB 使用入门
- mac pro扩展显示器 没有显示
- IOS7以上的UITableView顶部空白的问题
- Android进阶之_实现滑动的7种方式详解
- HDU 2600 War
- 算法-排序-选择排序(直接选择和堆排序)
- 数据结构基础5.1:树的遍历(递归与非递归实现)
- 检测亚像素级角点
- C语言中,注释不能嵌套
- 架构设计最佳实践与必备素养
- 111 js iframe表单提交后自动关闭 &
- java编程,格式化数字小数位
- 加密解密算法以及对应.Net实现