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

Re:有没有人输出每次路径,悲剧啊时间内存大1580K 63MS C 729B

Posted by mickeyandkaka at 2010-12-03 11:52:00 on Problem 3176
In Reply To:有没有人输出每次路径,悲剧啊时间内存大1580K 63MS C 729B Posted by:200831000719 at 2010-11-26 15:50:24
从底层开始 动态规划 
代码:
#include <stdio.h>
int max(int a,int b)
{
	return a>b?a:b;
}
int main()
{
	int i,j,n,a[351][351],b[351][351];
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
		for(j=0;j<=i;j++)
			scanf("%d",&a[i][j]);
	
	for(i=n-1;i>=0;i--)
		for(j=0;j<=i;j++)
		{
			if(i==n-1)
				b[i][j]=a[i][j];
			else
				b[i][j]=max(b[i+1][j],b[i+1][j+1])+a[i][j];
		}
		
	printf("%d\n",b[0][0]);
	return 0;	
}


我也想知道 0MS怎么实现的

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