Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:那位大侠帮我看看这段程序有什么错!老是WA

Posted by xiaoxiao at 2006-07-06 22:26:28 on Problem 2479
In Reply To:那位大侠帮我看看这段程序有什么错!老是WA Posted by:gaojinjun at 2006-07-05 10:57:39
对数据:
2
3
-1 2 3
3
-1 2 3
你的输出的两个结果不相同:
5
6
还有多了一句:printf("\n");
> #include <stdio.h>
> #include <stdlib.h>
> long b[50000]={0};
> long c[50000]={0};
> int a[50000]={0};
> int MaxSum(int m,int n)
> {
>     int i,j;
>     long max,sum=-500000000;
>     if(n<m||m<1)return 0;
>     for(i=1;i<=m;i++)
>     {
>         b[i]=b[i-1]+a[i];
>         c[i-1]=b[i];
>         max =b[i];
>         for(j=i+1;j<=i+n-m;j++)
>         {
>             b[j]=b[j-1]>c[j-1]?b[j-1]+a[j]:c[j-1]+a[j];
>             c[j-1]=max;
>             if(max<b[j])max=b[j];
>         }
>         c[i+n-m]=max;
>     }
>     for(j=m;j<=n;j++)
>        if(sum<b[j])sum=b[j];
>     return sum;
> }            
> int main(int argc, char *argv[])
> {
>   int i,j,k;
>   int n,m;
>   long sum[30]={0};
>   scanf("%d",&n);
>   for(i=0;i<n;i++)
>   {
>       scanf("%d",&m);
>       for(j=1;j<=m;j++)
>           scanf("%d",&a[j]);
>       printf("\n");
>       sum[i]=MaxSum(2,m);
>   }    
>    for(i=0;i<n;i++)
>       printf("%ld\n",sum[i]);   
>   system("PAUSE");	
>   return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator