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 2507409218 at 2018-02-27 14:24:24 on Problem 1163
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int maxroad[101][101];
int d[101][101];
int n;
int MAXroad(int i,int j)
{
	if (maxroad[i][j]!= -1)
	{
		return maxroad[i][j];
	}
	if (i == n) 
	{
		maxroad[i][j]=d[i][j];
	}
	else
	{
		int x = MAXroad(i + 1, j);
		int y = MAXroad(i + 1, j + 1);
		maxroad[i][j] = max(x, y) + d[i][j];
	}
	return maxroad[i][j];
}
int main()
{
	int i, j;
	cin >> n;
	for(i=1;i<=n;i++)
		for (j = 1; j <=i; j++)
		{
			cin >> d[i][j];
		}
	memset(maxroad, -1, sizeof(maxroad));
	cout << MAXroad(1,1) << endl;
	
}

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