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 Kanner at 2010-10-09 19:09:34 on Problem 1163
#include<iostream>

using namespace std;

#define MAX 100
int tri[MAX][2*MAX];

int main()
{
	int n;
	cin>>n;
	int i,j,first,last;
	for(i=0,first=n-1,last=n-1;i!=n;++i,--first,++last)
		for(j=first;j<=last;j+=2)
			cin>>tri[i][j];
	for(i=n-2,first=1,last=2*n-3;i>=0;--i,++first,--last)
	{
		int k=i+1;
		for(j=first;j<=last;j+=2)
		{
			int max;
			max=(tri[k][j-1]>tri[k][j+1])?tri[k][j-1]:tri[k][j+1];
			tri[i][j]+=max;
		}
	}
	cout<<tri[0][n-1]<<endl;
	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