| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1163题的我的源代码,求教呀!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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator