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

简单的dp,发代码纪念一下

Posted by liushengbing at 2010-06-01 20:55:59 on Problem 1163
/*我把三角形绕中轴旋转了处理的*/
#include <stdio.h>

#include <limits.h>

int dp_table[102];

int max_sum( int row )
{
	int i , j;
	int max_value ;

	for ( i = 0 ; i<= row+1 ; i++)
	{
		dp_table[i] = INT_MIN;
	}

	scanf("%d" , & dp_table[1]);
	
	for ( i = 2 ; i <= row ; i++)
	{
		for ( j = i ; j > 0 ; j--)
		{
			int new_value;
			
			scanf("%d" , &new_value);
			max_value = dp_table[j] + new_value;
			if ( dp_table[j] < dp_table[j-1])
			{
				max_value = dp_table[j-1] + new_value;
			}
			dp_table[j] = max_value;
		}
	}

	max_value = 0;
	for ( i = 1 ; i <= row ; i++)
	{
		if ( dp_table[i]>max_value)
		{
			max_value = dp_table[i];
		}
	}

	return max_value;



}


int main(void)
{
	int row;

	scanf("%d" , &row);
	printf("%d" ,max_sum(row) );

	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