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 |
我的一个递归算法,可是超时了,哪位仁兄帮帮忙!!!!#include<stdio.h> int a[100][100];//下三角形存放数据 int max1(int i,int j,int n)//递归函数 { int left,right; if((i==n-1)||(j==n-1))//到达边缘 return a[i][j]; left=max1(i+1,j,n);//左边 right=max1(i+1,j+1,n);//右边 return (left>right)? (left+a[i][j]):(right+a[i][j]); } main() { int n,i,j; scanf("%d",&n); for(i=0;i<n;i++) for(j=0;j<=i;j++) scanf("%d",&a[i][j]); printf("%d",max1(0,0,n)); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator