-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTRT.cpp
More file actions
32 lines (30 loc) · 702 Bytes
/
TRT.cpp
File metadata and controls
32 lines (30 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int dp[2001][2001];
int arr[2001];
int calculate(int be,int end,int year)
{
if(be>end)
return 0;
if(dp[be][end]!=-1)
return dp[be][end];
return (dp[be][end]=max(calculate(be+1,end,year+1)+year*arr[be],calculate(be,end-1,year+1)+year*arr[end]));
}
int main() {
int i,n,j;
cin>>n;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
dp[i][j]=-1;
}
for(i=0;i<n;i++)
cin>>arr[i];
cout<<calculate(0,n-1,1)<<endl;
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}