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

菜题留念,突破200题大关

Posted by bergkamp at 2010-02-16 16:40:39 on Problem 3186
#include <iostream>
using namespace std;
int n, r, v[2005], dp[2005][2005];
int dfs( int s, int e )
{
    int a, b;
    if ( dp[s][e] != -1 ) return dp[s][e];
    if ( s==e )
    {
        dp[s][e] = n*v[s];
        return dp[s][e];
    }
    a = dfs( s+1, e ) + (n-e+s) * v[s];
    b = dfs( s, e-1 ) + (n-e+s) * v[e];
    dp[s][e] = a > b ? a : b;
    return dp[s][e];
}
int main()
{
    int i, j;
    while ( cin>>n )
    {
        for ( i = 0; i < n; i++ )
        {
            cin>>v[i];
        }
        r = -1;
        for ( i = 0; i < 2005; i++ )
        {
            for ( j = 0; j < 2005; j++ )
            {
                dp[i][j] = -1;
            }
        }
        cout<<dfs( 0, n-1 )<<endl;
    }
    return 1;
}

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