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 xujihua at 2010-12-23 19:37:32 on Problem 1163
#include <iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int num[100][100],maxsum[100][100],n,i,j,ans;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    for(j=0;j<=i;j++)
    scanf("%d",&num[i][j]);
    maxsum[0][0]=num[0][0];
    for(i=1;i<n;i++)
    for(j=0;j<=i;j++)
    {if(j>0&&i<i)maxsum[i][j]=max(maxsum[i-1][j-1],maxsum[i-1][j])+num[i][j];
     else maxsum[i][j]=maxsum[i-1][j]+num[i][j];
    }
    ans=maxsum[n-1][0];
    for(j=0;j<n-1;j++)
    if(maxsum[n-1][j]<maxsum[n-1][j+1])
    ans=maxsum[n-1][j+1];
    printf("%d\n",ans);
    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