标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 374 Accepted Submission(s): 209
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define REP(i,a,b) for(int i=a;i<=b;i++) #define MS0(a) memset(a,0,sizeof(a)) using namespace std; typedef long long ll; const int maxn=100100; const int INF=(1<<29); int f[maxn],n; ll dp[maxn]; int main() { int T;cin>>T; while(T--){ cin>>n; REP(i,1,n-1) scanf("%d",&f[i]); ll ans=f[1]*n; MS0(dp); REP(i,0,n-2) dp[i]=-INF; dp[0]=0; REP(i,1,n-2){ REP(j,0,i){ dp[i]=max(dp[i],dp[i-j]+f[j+1]-f[1]); //cout<<i<<" "<<dp[i]<<endl; } } ans+=dp[n-2]; printf("%I64d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/--560/p/4959602.html