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

= =、写的好漂亮?

Posted by JamesHarden at 2016-07-11 10:11:46 on Problem 3186
#include<iostream>
#include<cstdio>
#include<math.h>
#include<queue>
#include<map>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f
#define PI acos(-1.0)

const int N=1e3+10;

int a[N*2];
int dp[N*2][N*2];
int n;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    memset(dp,0,sizeof(dp));

    for(int i=n;i>=1;i--){
        for(int j=i;j<=n;j++)
            dp[i][j]=max(dp[i+1][j]+(n-(j-i))*a[i],dp[i][j-1]+(n-(j-i))*a[j]);
    }
    cout<<dp[1][n]<<endl;
}
/*

5
1
3
1
5
2

*/

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