| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 350 人关注过本帖
标题:帮忙看看,谢谢了。
只看楼主 加入收藏
枫叶无痕
Rank: 2
等 级:论坛游民
帖 子:80
专家分:30
注 册:2011-2-10
结帖率:73.91%
收藏
已结贴  问题点数:20 回复次数:3 
帮忙看看,谢谢了。
Problem Description
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

 

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

 

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

 

Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5
 

Sample Output
Case 1:
14 1 4

Case 2:
7 1 6




帮忙看看错在哪里了?
#include<stdio.h>
main()
{
    long i,j,t,n,str[100001],k[100001],f[100001],h,c;
    while(scanf("%d",&t)!=EOF)
    {
        for(i=1;i<=t;i++)
        {
            scanf("%d",&n);
            for(j=1;j<=n;j++)
            {
                scanf("%d",&str[j]);
                if(j==1)
                {k[j]=str[j];}
                else
                {k[j]=k[j-1]+str[j];}
            }
            h=k[1];
            for(j=1;j<=n;j++)
            {
                f[j]=k[j];
                if(f[j]>h)
                {
                    h=f[j];
                }
            }
            printf("Case %d:\n",i);
            printf("%d ",h);
            for(c=1;c<=n;c++)
            {
                if(k[c]==h)
                {printf("%d %d\n",n-c,c);
                break;}
            }
            if(i!=t)
            {printf("\n");}
        }
    }
}
搜索更多相关主题的帖子: test 
2011-04-03 16:21
千岛龙崎
Rank: 2
等 级:论坛游民
帖 子:5
专家分:20
注 册:2011-3-19
收藏
得分:0 
    long i,j,t,n,str[100001],k[100001],f[100001],h,c;
100001?请问你的计算机有多少内存,够分配吗?
2011-04-03 16:46
千岛龙崎
Rank: 2
等 级:论坛游民
帖 子:5
专家分:20
注 册:2011-3-19
收藏
得分:20 
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).
T是比较个数,改成[20],100000是数的大小,long够用了,就这样,要不你的计算机就得预先留出300000个long的空间。
2011-04-03 16:52
vandychan
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
注 册:2010-8-20
收藏
得分:0 
有点难度

到底是“出来混迟早要还”还是“杀人放火金腰带”?
2011-04-04 21:00
快速回复:帮忙看看,谢谢了。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041981 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved