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

querdaizhi 2011-07-25 05:33:38
http://acm.hdu.edu.cn/showproblem.php?pid=1087

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;
}
...全文
166 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rikiss 2011-07-26
  • 打赏
  • 举报
回复
逻辑有错,计算当前节点的max应该是当前节点之前的所有t小于当前节点t的所有节点中,最大的max加上当前节点的t的和
简单写了一下,提交accept了,LZ看下
for(i=1;i<=n;i++)
{
cin >> a[i].t;
int tempMax = 0;
for(int j =0 ; j< i; j++)
{
if(a[j].t < a[i].t)
{
if(a[j].max > tempMax)
{
tempMax = a[j].max;
}
}
}
a[i].max = tempMax + a[i].t;
}

33,027

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧