标签:des style blog http color java os strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1585 Accepted Submission(s):
756
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 const int maxn = 105; 7 const int oo = 99999999; 8 int dp[maxn][maxn]; 9 int a[maxn],sum[maxn]; 10 int main() 11 { 12 int T,t,n; 13 scanf("%d",&T); 14 for (t = 1; t<=T; t++) 15 { 16 scanf("%d",&n); 17 for (int i=1; i<=n; i++) 18 scanf("%d",&a[i]); 19 sum[0] = 0; 20 for (int i=1; i<=n; i++) 21 sum[i]=sum[i-1]+a[i]; 22 memset(dp,0,sizeof(dp)); 23 for (int i=1; i<=n; i++) 24 for (int j=i+1; j<=n; j++) 25 dp[i][j]=oo; 26 for (int len=1; len<n; len++) 27 { 28 for (int i=1; i<=n-len; i++) 29 { 30 int j = i + len; 31 for (int k=1; k<=j-i+1; k++) 32 dp[i][j]=min(dp[i][j],dp[i+1][i+k-1]+dp[i+k][j]+(k-1)*a[i]+k*(sum[j]-sum[i+k-1])); 33 } 34 } 35 printf("Case #%d: %d\n",t,dp[1][n]); 36 } 37 return 0; 38 }
标签:des style blog http color java os strong
原文地址:http://www.cnblogs.com/lxm940130740/p/3890804.html