一道ACM题,为什么WA了,求解释啊

Nowadays,akindofchessgamecalled“SuperJumping!Jumping!Jumping!”isverypopularinHDU.Mayb... 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 <iostream>
using namespace std;

typedef struct
{
long int max;
long int t;
}node;

int main()
{
long int n,i;
while(cin >> n&&n)
{
node a[1010];
a[0].max =0;
a[0].t=0;
for(i=1;i<=n;i++)
{
cin >> a[i].t;
if(a[i].t > a[i-1].t)
{
a[i].max = a[i].t+a[i-1].max;
}
else if(a[i].t < a[i-1].t)
{
a[i].max = a[i].t;
}
else if(a[i].t = a[i-1].t)
{
a[i].max = a[i].t;
}
}
long int max=0;
for(i=1;i<=n;i++)
if(a[i].max > max)
max =a[i].max;
cout<<max<<endl;
}
return 0;
}
展开
 我来答
porker2008
2011-07-25 · TA获得超过1.4万个赞
知道大有可为答主
回答量:7066
采纳率:62%
帮助的人:1.1亿
展开全部
#include <iostream>
using namespace std;

typedef struct
{
long int max;
long int t;
}node;

int main()
{
long int n,i,j;
while(cin >> n&&n)
{
node a[1010];
a[0].max =0;
a[0].t=0;
for(i=1;i<=n;i++)
{
cin >> a[i].t;
a[i].max = a[i].t;
for(j=i-1;j>=0;j--)
{
if(a[j].t < a[i].t && a[j].max + a[i].t > a[i].max)
{
a[i].max = a[j].max + a[i].t;
}
}
}
long int max=0;
for(i=1;i<=n;i++)
if(a[i].max > max)
max =a[i].max;
cout<<max<<endl;
}
return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式