Super Jumping! Jumping! Jumping!
来源:互联网 发布:网络代刷信誉兼职中心 编辑:程序博客网 时间:2024/06/02 06:13
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
4
10
3
题意求出最大连续递增子序列,对于对于第一个数dp[1]=str[1],dp[i]只有两种结果(1)dp[i]=str[i](2)dp[i]=str[i]+递增到i的最大值(每一项都小于str[i])sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j,a[i]<a[j]
#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define N 1005#define INS 1000000 //定义一个大数int str[N]={0},dp[N]={0}; //初始化部分值int main(){ int n; //freopen("e:\\in,txt","r",stdin); while(scanf("%d",&n)==1&&n!=0) { for(int i=1;i<=n;i++) scanf("%d",&str[i]); for(int i=1;i<=n;i++) { int ans=-INS; for(int j=0;j<i;j++) { if(str[i]>str[j]) ans=max(ans,dp[j]); //符合条件更新ans } dp[i]=ans+str[i]; } int re=-INS; for(int i=1;i<=n;i++) re=max(re,dp[i]); printf("%d",re); } return 0;}
0 0
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- Super Jumping! Jumping! Jumping!
- AngularJs之新手小白入门篇
- 01背包变形(poj2184)
- 属性 选择器 空格规范
- 第217讲:Spark Shuffle中HashShuffleWriter工作机制和源码详解
- OWASP TOP 10
- Super Jumping! Jumping! Jumping!
- 用数学思维解决高级阶乘问题
- HAUT校赛 魔法宝石 暴力
- 死锁的定义、产生原因、必要条件、避免死锁和解除死锁的方法
- 有36匹马,六个跑道。没有记时器等设备,用最少的比赛次数算出跑的最快的前3匹马
- BZOJ3729: Gty的游戏
- MyBatis
- php导入Excel问题
- Tensorflow-MNIST数字识别练习代码