Super Jumping! Jumping! Jumping!
来源:互联网 发布:CMS淀粉 编辑:程序博客网 时间:2024/06/05 07:06
题意
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
分析
仍旧从后往前推,用一个结构体一个为数字原先大小,另一个为所求的最大值,若后一个数字原先更大,则加上最大值加上后一个的最大值。
#include<bits/stdc++.h>using namespace std;struct f{ int x; long long y;}a[1005];int main(){ int n; while(scanf("%d",&n)&&n) { long long maxm; for(int i=0;i<n;i++) { scanf("%d",&a[i].x); a[i].y=a[i].x; } for(int i=n-2;i>=0;i--) { maxm=0; for(int j=n-1;j>i;j--) { if(a[j].x>a[i].x&&a[j].y>maxm) maxm=a[j].y; } a[i].y+=maxm; } int mmaxm=0; for(int i=0;i<n;i++) { if(a[i].y>mmaxm) mmaxm=a[i].y; } cout<<mmaxm<<endl; }}
- 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!
- sas统计分析学习笔记(五)
- MAC上读出usb
- Lucene搜索引擎+HDFS+MR完成垂直搜索
- 匈牙利算法
- Flask-hello程序
- Super Jumping! Jumping! Jumping!
- 今天写了一条把我两个月职业生涯学到的SQL知识全用上了的语句
- 关闭服务器windows server的IE浏览器的增强安全配置
- 文本相关性排序
- 用javadoc命令生成api帮助文档
- MySQL的InnoDB索引原理详解
- 刷题——Dollar Dayz POJ
- Android 利用 RXJAVA interval 操作符 实现 计时器 功能
- 数据冒险之图以及最小生成树