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

请教大家,这个哪里错了(有注释)谢谢了!

Posted by mightyvoice at 2009-03-26 17:45:01 on Problem 1050
如果能指出错误,在下感激不禁,谢谢了!
#include <cstdlib>
#include <stdio.h>

using namespace std;

int max(int x,int y)
{  if(x>y) return(x);
   else return(y);
}

int main(int argc, char *argv[])
{   int b[101][101],a[101][2],d[101],sum=0,i,j,n,k,m,ma;
   scanf("%d",&n);
    for(i=1;i<=n;i++)//输入
       for(j=1;j<=n;j++)
         {  scanf("%d",&b[i][j]);
            if(i==1&&j==1) sum=b[i][j];
            if(b[i][j]>sum) sum=b[i][j];
         }
   if(n>1)
   {
    for(i=1;i<=n;i++)//搜索任意两行及其中间行组成的矩形能形成的最大值。
      { for(j=i;j<=n;j++)
         {   for(k=1;k<=n;k++) { d[k]=0;a[k][0]=0;a[k][1]=0;}
             for(m=1;m<=n;m++)
               for(k=i;k<=j;k++)
               d[m]+=b[k][m];// 算m列的数之和
             a[n][0]=0;a[n][1]=d[n];

//a[k][0]表示不取第k列时从k列到n列能组合出的最大值;
//a[k][1]表示取第k列时从k列到n列能组合出的最大值;
             for(k=n-1;k>=1;k--)//动态规划
                {  a[k][0]=max(a[k+1][0],a[k+1][1]);
                   a[k][1]=d[k];
                   for(m=k+1;m<=n;m++)//寻找从k+1开始的最大连续正整数列
                   {  if(d[m]<=0) break; 
                      else a[k][1]+=d[m];
                   }
                 }
                ma=max(a[1][0],a[1][1]);
                if(sum<ma) sum=ma;
          }
        } 
    }
    printf("%d\n",sum);   
    system("PAUSE");
    return EXIT_SUCCESS;
}

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