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

20行 16ms

Posted by 3015216017 at 2018-09-03 23:46:29 on Problem 3176
#include <algorithm>
#include <stdio.h>
using namespace std;
int dp[355][355];
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < i + 1; j++){
			scanf("%d", &dp[i][j]);
			if(i > 0){
				if(j - 1 >= 0)
					dp[i][j] = dp[i][j] + max(dp[i-1][j], dp[i - 1][j - 1]);
				else
					dp[i][j] = dp[i][j] + dp[i - 1][j];
			}
		}
	printf("%d\n", *(max_element(dp[n - 1], dp[n - 1] + n)));
	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