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
不过我认为它的解法有些问题,
我的解法:
#include <iostream.h>
#include <stdlib.h>
int main() {
int n,i,j;
cin>>n; //输入数组的大小
int* array = (int *)malloc(n*sizeof(int));
int* maxA = (int *)malloc(n*sizeof(int));
for(i=0; i<n; i++) {
cin>>array[i];
maxA[i] = array[i];
}
int maxSum = array[0];
int k=0;
for(i=0; i<n; i++) {
k = i; //用来保存上一个最大值的位置
for(j=i+1; j<n; j++) {
//求以array[i]开始的序列的最大值
if(array[j] > array[k]) {//当前最大值
maxA[i] += array[j];
k = j;
if( maxA[i] > maxSum)//overall maximun
maxSum = maxA[i];
}
}
}
cout<<"The result is: "<<maxSum<<endl;
return 0;
}
欢迎批评指正
ps:怎么把输入和输出的格式弄成题目要求的那样呢?
分享到:
相关推荐
杭电hdu acm资料所用杭电的acm题
HDU_ACM培训课件(完整版) HDU_ACM培训课件(完整版) HDU_ACM培训课件(完整版) HDU_ACM培训课件(完整版)
杭电 hdu acm 第1084题的解法,ac过了,是一位学长教我的.内有一些中文说明.
hdu_2102_passed_sorce
此程序为hdu的acm2010题,就是解决水仙花数问题
模式识别_hdu_期末复习资料集合_试卷笔记.zip
HDU_ACM_1002_大数相加C源代码,利用字符串处理
数字图像处理_hdu_期末复习资料_试卷等.zip
数字图像处理总ppt_hdu_许老师.pdf
高级计算机图形学_mm的_重点笔记_hdu_吴xy.pdf
HDU一部分题目原码,大部分是可运行的,可能有几题不完整
B_(HDU_1231)(最大子段和,分治).cpp
杭电acm解题报告 详细解析2000-2099 适合acm初学者
杭电OJ部分答案,可以很简单的解决a+b求和问题及其他问题。
For a positive integer n, let’s denote function f(n,m) as the m-th smallest integer x that x>n and gcd(x,n)=1. For example, f(5,1)=6 and f(5,5)=11. You are given the value of m and (f(n,m)?...
hdu题解的答案十分简单的一个题,思路清晰,特别简单
hdu 3378 三国杀标程 解题报告
动态规划DP题解 POJ HDU部分动态规划DP题解
基础算法类 ACM 入门 杭电OJ 11页题目题解,算法入门的时候刷题可以参考 搜集整理起来了比单个去搜题解方便快捷
里面包含:实验1~8的源代码,ISE软件直接导入就能使用、课件PPT、3份实验报告、实验要求与评分标准。