标签:
Description
Input
Output
Sample Input
1 7 1 2 4 4 5 4 3
Sample Output
38
1 //2016.8.6 2 //区间dp 3 #include<iostream> 4 #include<cstdio> 5 #include<cstring> 6 7 using namespace std; 8 9 typedef long long ll; 10 const int inf = 0x3f3f3f3f; 11 ll a[70], dp[70][70]; 12 13 int main() 14 { 15 int T, n; 16 cin>>T; 17 while(T--) 18 { 19 cin>>n; 20 for(int i = 0; i < n; i++) 21 scanf("%lld", &a[i]); 22 23 for(int i = 0; i < n; i++) 24 for(int j = 0; j < n; j++) 25 if(j-i<=20) 26 dp[i][j] = a[i]*(1<<(j-i+1)); 27 else 28 dp[i][j] = inf; 29 30 for(int i = 0; i < n; i++) 31 for(int j = 0; j < n; j++) 32 for(int k = i; k < j; k++) 33 dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]); 34 35 cout<<dp[0][n-1]<<endl; 36 } 37 38 return 0; 39 }
标签:
原文地址:http://www.cnblogs.com/Penn000/p/5745021.html