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 zgr0629 at 2009-04-03 14:34:54
从下往上算。

0MS

#include <stdio.h>
int n,data[105][105],step[105][105];
int main()
{
	int i,j,t,max=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<=i;j++)
		{
			scanf("%d",&data[i][j]);
			step[i][j]=-1;
		}
	}

	for(i=0;i<n;i++)
		step[n-1][i]=data[n-1][i];

	for(i=n-2;i>=0;i--)
	{
		for(j=0;j<=i;j++)
		{
			max=0;
			t=step[i+1][j]+data[i][j];
			if(max<t)
				max=t;
			t=step[i+1][j+1]+data[i][j];
			if(max<t)
				max=t;
			step[i][j]=max;
		}
	}
	printf("%d",step[0][0]);
	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