Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
菜题留念,突破200题大关#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator