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行代码~

Posted by ffouzhe at 2016-09-07 23:37:38 on Problem 3186
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=2000+10;
int d[MAXN][MAXN],a[MAXN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) 
	d[i][i]=n*a[i];
	for(int i=n-1;i>0;i--)
	 for(int j=i+1;j<=n;j++)
	 d[i][j]=max(d[i+1][j]+(n-j+i)*a[i],d[i][j-1]+(n-j+i)*a[j]);
	printf("%d\n",d[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