forwhat00  
 1 #include <iostream> 
 2 #include <cmath> 
 3 #include <algorithm> 
 4 #define REP(i, begin, end) for (int i = begin; i <= end; i ++) 
 5 #define DEBUG if(1)
 6 #define INF 5000*100+100
 7 using namespace std; 
 8 int dp[105][105], D[105], sum[105],NN,N; 
 9 int main(){ 
10     int t; cin>>NN; 
11     REP(CASE,1,NN){ 
12         int n; cin>>N; 
13         sum[0] = 0; 
14         REP(i,0,N){ 
15             REP(j,0,N){ 
16                 if (j <= i) 
17                     dp[i][j] = 0; 
18                 else 
19                     dp[i][j] = INF; 
20             } 
21         } 
22         REP(i,1,N){ 
23             cin>>D[i]; 
24             sum[i] = sum[i-1] + D[i]; 
25         } 
26         REP (len,1,N){ 
27             REP (i,1,N){ 
28                 int j = i + len; 
29                 REP(k,i,j){ 
30                     dp[i][j] = min(dp[i][j], 
31                             dp[i+1][k]+//先排出第k个前的
32                             (k-i)*D[i]+//如果第i个是第k次排出
33                             dp[k+1][j]+//加上k后的
34                             (k-i+1)*(sum[j]-sum[k])//k后的加一倍
35                         ); 
36                 } 
37             } 
38         } 
39         cout<<"Case #"<<CASE<<": "<<dp[1][N]<<endl;
40     } 
41     return 0; 
42 }

https://vjudge.net/contest/382410#problem/G

posted on 2020-07-17 01:11  forwhat00  阅读(186)  评论(0编辑  收藏  举报