标签:
题目:这里
题意:
感觉并不能表达清楚题意,所以
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 #define inf 0x3f3f3f3f 8 const int M = 1e4 + 10; 9 int dp[M],a[M]; 10 11 int max(int x,int y){return x>y?x:y;} 12 13 int main() 14 { 15 int t,n; 16 scanf("%d",&t); 17 while (t--){ 18 scanf("%d",&n); 19 for (int i=1 ; i<n ; i++) { 20 scanf("%d",&a[i]); 21 if (i!=1) a[i]-=a[1]; 22 } 23 //int pa=n*2-2; 24 for (int i=0 ; i<=n ; i++) dp[i]=-inf; 25 dp[0]=0;//dp[1]=a[1]; 26 for (int i=2 ; i<n ; i++) { 27 for (int j=0 ; j+i-1<=n-2 ; j++) 28 dp[i+j-1] = max(dp[i+j-1],dp[j]+a[i]); 29 } 30 printf("%d\n",dp[n-2]+n*a[1]); 31 } 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/JJCHEHEDA/p/5873314.html