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

1163题的我的源代码,求教呀!

Posted by zhangxiaofan at 2012-05-26 21:51:05
1163题的我的源代码,运行了很多遍,总是说答案错了,求那位仁兄赐教一番,小弟不胜感激!
#include<stdio.h>
int main()   
{   
    int r,i,j,max,a[100][100];   
    scanf("%d",&r);
    if(r<=1&&r>100)
		exit(0);
    for(i=0;i<=r-1;i++) 
	{
		for(j=0;j<=i;j++)   
		{
			scanf("%d",&a[i][j]);    
		}
    }
		a[1][0]+=a[0][0];   
		a[1][1]+=a[0][0];
		a[2][0]+=a[1][0];
		a[2][2]+=a[1][1];
	    if(a[1][0]>=a[1][1])
		{
			a[2][1]+=a[1][0];
		}
		else
		{
			a[2][1]+=a[1][1];
		}
	if(r==2)
		{
			max=a[1][0];
			if(a[1][1]>max)
			{
				max=a[1][1];
			}
			printf("%d\n",max);
		}
	else if(r>2)
    {
		for(i=3;i<=r-1;i++)   
        for(j=1;j<=r-1;j++)   
        {
			if(a[i-1][j]>=a[i-1][j-1])
			{	
				a[i][j]+=a[i-1][j];   
            
			}	
				else 
			{
				a[i][j]+=a[i-1][j-1];
			}
		}
		max=a[r-1][0];   
		for(j=1;j<=r-1;j++) 
		{
			if(a[r-1][j]>max)
			{
				max=a[r-1][j];
			}
		}
		printf("%d\n",max);
	}
} 

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